WebDriverException:无法使用 GeckoDriver Firefox 和 Selenium Java 连接到二进制 FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe)
WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) with GeckoDriver Firefox and Selenium Java
使用Selenium 3.1.0,firefox最新版本72.0,默认firefox驱动2.53.1
这是我的代码
System.setProperty("webdriver.gecko.driver" ,"C:\Users\sindhusha.tummala\Downloads\geckodriver.exe");
driver = new FirefoxDriver();
我仍然收到错误
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
有人可以帮忙吗
这个错误信息...
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
...暗示 GeckoDriver 二进制文件(可执行文件)无法 initiate/spawn 新的 浏览上下文 即 Firefox 浏览器 会话,因为它无法找到 FirefoxBinary。
当 Firefox 未安装在默认位置或根本未安装时,会出现此问题。
解决方案
解决这个问题:
- 如果 Firefox 没有全部安装,您必须安装它。
- 如果 Firefox 没有安装在默认位置你需要通过 Firefox绝对路径Firefox二进制通过参数
firefox_binary
如下:
代码块:
public class A_Firefox_binary
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\path\to\firefox.exe");
WebDriver driver = new FirefoxDriver(options);
driver.get("https://whosebug.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
额外考虑
确保:
- 将 JDK 升级到最近的水平 JDK 8u222。
- 将 Selenium 升级到当前水平 Version 3.141.59。
- 将 GeckoDriver 升级到 GeckoDriver v0.26.0 级别。
- GeckoDriver 出现在所需位置。
- GeckoDriver 具有非 root 用户的可执行权限。
- 将 Firefox 版本升级到 Firefox v70.0 级别。
- 通过IDE和[=44]清理您的项目工作区 =]重建你的项目只需要依赖。
- (WindowsOS only) 使用 CCleaner 工具清除执行 OS 之前和之后的所有琐事 测试套件.
- (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 在你的 Test Suite 执行前后。
- 如果您的基础 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
- 系统重启。
- 以非 root 用户身份执行
Test
。
- 始终在
tearDown(){}
方法中调用 driver.quit()
以优雅地关闭和销毁 WebDriver 和 Web Client 实例.
结尾
您可以在以下位置找到一些相关讨论:
- How to open Firefox Developer Edition through Selenium
- Python 3.5 - “Geckodriver executable needs to be in PATH”
使用Selenium 3.1.0,firefox最新版本72.0,默认firefox驱动2.53.1 这是我的代码
System.setProperty("webdriver.gecko.driver" ,"C:\Users\sindhusha.tummala\Downloads\geckodriver.exe");
driver = new FirefoxDriver();
我仍然收到错误
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
有人可以帮忙吗
这个错误信息...
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files\Mozilla Firefox\firefox.exe) on port 7055;
...暗示 GeckoDriver 二进制文件(可执行文件)无法 initiate/spawn 新的 浏览上下文 即 Firefox 浏览器 会话,因为它无法找到 FirefoxBinary。
当 Firefox 未安装在默认位置或根本未安装时,会出现此问题。
解决方案
解决这个问题:
- 如果 Firefox 没有全部安装,您必须安装它。
- 如果 Firefox 没有安装在默认位置你需要通过 Firefox绝对路径Firefox二进制通过参数
firefox_binary
如下: 代码块:
public class A_Firefox_binary { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe"); FirefoxOptions options = new FirefoxOptions(); options.setBinary("C:\path\to\firefox.exe"); WebDriver driver = new FirefoxDriver(options); driver.get("https://whosebug.com"); System.out.println("Page Title is : "+driver.getTitle()); driver.quit(); } }
额外考虑
确保:
- 将 JDK 升级到最近的水平 JDK 8u222。
- 将 Selenium 升级到当前水平 Version 3.141.59。
- 将 GeckoDriver 升级到 GeckoDriver v0.26.0 级别。
- GeckoDriver 出现在所需位置。
- GeckoDriver 具有非 root 用户的可执行权限。
- 将 Firefox 版本升级到 Firefox v70.0 级别。
- 通过IDE和[=44]清理您的项目工作区 =]重建你的项目只需要依赖。
- (WindowsOS only) 使用 CCleaner 工具清除执行 OS 之前和之后的所有琐事 测试套件.
- (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint 在你的 Test Suite 执行前后。
- 如果您的基础 Web 客户端 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web 客户端.
- 系统重启。
- 以非 root 用户身份执行
Test
。 - 始终在
tearDown(){}
方法中调用driver.quit()
以优雅地关闭和销毁 WebDriver 和 Web Client 实例.
结尾
您可以在以下位置找到一些相关讨论:
- How to open Firefox Developer Edition through Selenium
- Python 3.5 - “Geckodriver executable needs to be in PATH”