线程“主” org.openqa.selenium.WebDriverException中的异常:无法使用webdriver.firefox.marionette连接到二进制FirefoxBinary

时间:2018-10-30 04:38:25

标签: selenium firefox selenium-webdriver webdriver geckodriver

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"
    }

2 个答案:

答案 0 :(得分:0)

尝试一下:

  1. 确保您的FF版本为63(最新版本为2018年10月30日)
  2. 确保您的硒版本为3.14
  3. 确保您已下载最新的geckodriver 0.23(https://github.com/mozilla/geckodriver/releases
  4. 确保geckodriver.exe位于C:\\的根目录中(或更改下面的路径)
  5. 使用: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 实例优雅地。

Supported Platforms

下表显示了geckodriver版本,受支持的Firefox版本和所需的Selenium版本之间的映射:

GeckoDriver_SupportedPlatforms_small