maven - 使用 Selenium 启动 Firefox

标签 maven selenium firefox

我正在尝试使用 Firefox 并在 Google 上进行简单搜索,但我只能启动 Firefox。应该在代码中编辑什么才能顺利运行?我正在使用使用 maven 依赖项运行的 Firefox Quantum 57。

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirefoxLaunch
{
    @Test
    public static void main(String [] args) {
        WebDriver driver;
        driver = new FirefoxDriver();
        driver.get("https://google.com");
        WebElement element =driver.findElement(By.name("q"));
        element.sendKeys("FirefoxDriver Search Function");
        driver.quit();
    }
}

最佳答案

工作时:

  • Selenium v​​3.x 客户
  • Firefox Quantum v70.x

您需要下载 来自这个 link 的二进制文件并将其保存在您的系统中,然后通过 System.setProperty() 行提供 GeckoDriver 二进制文件的绝对路径,如下所示:

System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");

关于maven - 使用 Selenium 启动 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47410233/

相关文章:

java - OSGI bundle 已激活,但使用 DS 和 Apache Karaf 时从未创建组件

java - Maven cargo : Integration Test runs before cargo deploys war

javafx-maven-plugin mac pkg 安装程序不显示应用程序图标

java - 如何使用Xpath选择特定容器的span元素(<div>由CSS类定义)?

python - 如何从网站中提取信息?

javascript - 通过javascript以编程方式将证书导入firefox受信任的根CA

css - 如何修改firefox Quantum dev工具字体?

maven - 无法执行目标 org.apache.maven.plugins :maven-surefire-plugin:2. 12 :test (default-test) on project.

python - CSS 定位器 : unable to locate element via code

html - 在后台播放网页中的声音文件