gpt4 book ai didi

Java Selenium Gecko 驱动程序未加载

转载 作者:行者123 更新时间:2023-11-30 06:56:20 25 4
gpt4 key购买 nike

问题:

当我使用 testNG 运行时,geckodriver.exe 未加载。 Firefox 将启动,但 selenium 无法连接到浏览器,并且出现错误:

Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. ....

我的设置:

  • Windows 7
  • Eclipse NEON 3
  • Selenium 3.0.1
  • Geckodriver v0.13.0(使用的是 v0.11.1)
  • 火狐48.0.2

首先,我使用 Java 和 selenium 创建了一个快速测试。它只是打开浏览器并导航到页面。当它运行时,我看到 geckodriver 进程,然后 firefox 进程出现在任务管理器中。

然后我按照 GURU99 网站的设置使用 Maven 和 testNG 创建了一个新项目。我已将 selenium 和 testNG 添加到 pom.xml 文件中。

我使用了将项目转换为 testNG(xml 文件)并设置运行配置来运行 XML 文件。

当我运行测试时,我可以看到 firefox 进程,然后 ff 启动。但 gecko 驱动程序进程从未启动。

这是我的代码(不包括导入):

public class NewTest {

private WebDriver driver;

@Test
public void test01() {
driver.get("http://www.startpage.com");
System.out.println("Pge title " + driver.getTitle());
}

@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.gecko.driver", "c:\\selenium\\geckodriver.exe");
driver = new FirefoxDriver();
}

@AfterTest
public void afterTest() {
driver.quit();
}
}

最佳答案

您错过了设置 Marionette 功能,例如

System.setProperty("webdriver.gecko.driver", <<Your driver path here>>);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.MARIONETTE, true);
cap.setCapability(FirefoxDriver.BINARY, <<Your firefox.exe path here>>);
cap.setCapability(FirefoxDriver.PROFILE, <<Your firefox profile here>>);
driver = new FirefoxDriver(cap);

我正在使用上面的内容,它的效果非常好!

有关更多信息,请参阅:Selenium 3 using Firefox Geckodriver .

关于Java Selenium Gecko 驱动程序未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41727624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com