public class TestClass1 {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/signin");
driver.close();
System.exit(0);
}
}
此代码的结果如下:
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
[
{
"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"minVersion":"63.0","maxVersion":"63.*"
}
],
"targetPlatforms":[],
"seen":true,
"dependencies":[],
"hasEmbeddedWebExtension":false,
"userPermissions":null,
"icons":{},
"blocklistState":0,
"blocklistURL":null,
"startupData":null,
"hidden":true,
"location":"app-system-defaults"
}
答案 0 :(得分:0)
尝试一下:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
如果它不起作用,请尝试将FF降级到以前的62版本,然后尝试一下。
仅供参考,请阅读此Difference between webdriver.firefox.marionette & webdriver.gecko.driver
支持的版本: https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/Support.html
答案 1 :(得分:0)
在使用 Selenium 3.x , GeckoDriver 和 Firefox 时,您需要下载最新版本的 GeckoDriver 。来自mozilla/geckodriver的strong>,将其提取并通过 Key System.setProperty()行提及 GeckoDriver 二进制文件的绝对路径 > webdriver.gecko.driver
,而不是webdriver.firefox.marionette
,如下所示:
public class TestClass1 {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\path\\to\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/signin");
driver.quit();
}
}
注意:请始终在driver.quit()
方法内调用tearDown(){}
以关闭并销毁 WebDriver 和 Web Client 实例优雅地。
下表显示了geckodriver版本,受支持的Firefox版本和所需的Selenium版本之间的映射: