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

查看:75
本文介绍了WebDriverException:无法使用GeckoDriver Firefox和Selenium Java连接到二进制FirefoxBinary(C:\ Program Files \ Mozilla Firefox \ firefox.exe)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Selenium 3.1.0,firefox最新版本72.0,默认firefox驱动程序2.53.1这是我的代码

Using Selenium 3.1.0, firefox latest version 72.0, default firefox driver 2.53.1 here is my code

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 二进制文件(可执行文件)无法启动/产生新的浏览上下文,即 Firefox浏览器会话,无法找到FirefoxBinary.

...implies that the GeckoDriver binary (executable) was unable to initiate/spawn a new Browsing Context i.e. Firefox Browser session as it was unable to locate the FirefoxBinary.

Firefox 未安装在默认位置或完全未安装时,会出现此问题.

This issue arises when Firefox is not installed at the default location or is not installed at all.

要解决此问题:

  • 如果尚未完全安装 Firefox ,则必须安装.
  • 如果未在默认位置安装 Firefox ,则需要通过参数传递 Firefox 二进制文件的绝对路径.firefox_binary 如下:
  • 代码块:

  • If Firefox is not al all installed you have to install it.
  • If Firefox is not installed at the default location you need to pass the absolute path of the Firefox binary through the argument firefox_binary as follows:
  • Code block:

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://stackoverflow.com");
        System.out.println("Page Title is : "+driver.getTitle());
        driver.quit();
    }
}

确保:

  • JDK 升级到最新级别 JDK 8u222 .
  • 升级到当前级别> 版本3.141.59 > .
  • GeckoDriver 升级到 GeckoDriver v0.26.0 级别.
  • GeckoDriver存在于所需位置.
  • GeckoDriver对非root用户具有可执行权限.
  • Firefox 版本升级到 Firefox v70.0 级别.
  • 通过 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项.
  • (仅仅WindowsOS )使用 CCleaner 工具,可消除执行 Test Suite 之前和之后的所有操作系统琐事.
  • (仅仅LinuxOS )来卸载. Revo Uninstaller 并安装最新版本的 Web客户端 GA和发行版.
  • 进行系统重启.
  • 以非root用户身份执行 Test .
  • 始终在 tearDown(){} 方法中调用 driver.quit()以关闭&优雅地销毁 WebDriver Web Client 实例.
  • Upgrade JDK to recent levels JDK 8u222.
  • Upgrade Selenium to current levels Version 3.141.59.
  • Upgrade GeckoDriver to GeckoDriver v0.26.0 level.
  • GeckoDriver is present in the desired location.
  • GeckoDriver is having executable permission for non-root users.
  • Upgrade Firefox version to Firefox v70.0 levels.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
  • (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your Test as a non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

您可以在以下位置找到一些相关的讨论:

You can find a couple of relevant discussions in:

这篇关于WebDriverException:无法使用GeckoDriver Firefox和Selenium Java连接到二进制FirefoxBinary(C:\ Program Files \ Mozilla Firefox \ firefox.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆