Selenium 2.53 不适用于 Firefox 47 [英] Selenium 2.53 not working on Firefox 47

查看:19
本文介绍了Selenium 2.53 不适用于 Firefox 47的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用带有 WebDriver 的 Firefox 时出错.

I am getting error while using Firefox with WebDriver.

org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.

  • Firefox 版本:47.0
  • 硒:2.53.0
  • Windows 10 64 位
  • 有没有人遇到类似的问题或知道解决方案是什么?它在 Chrome 中运行良好,但在 Firefox 中没有任何 URL 被加载.

    Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.

    推荐答案

    遗憾的是 Selenium WebDriver 2.53.0 与 Firefox 47.0 不兼容.处理 Firefox 浏览器的 WebDriver 组件 (FirefoxDriver) 将停止使用.从 3.0 版本开始,Selenium WebDriver 将需要 geckodriver 二进制文件来管理 Firefox 浏览器.更多信息这里此处.

    Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver binary to manage Firefox browsers. More info here and here.

    因此,为了使用 Firefox 47.0 作为带有 Selenium WebDriver 2.53.0 的浏览器,您需要下载 Firefox 驱动程序(从 0.8.0 版开始,这是一个名为 geckodriver 的二进制文件,以前称为 wires)并将其绝对路径导出到变量 webdriver.gecko.driver 作为 Java 代码中的系统属性:

    Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver as of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driver as a system property in your Java code:

    System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
    

    幸运的是,库 WebDriverManager 可以为您完成这项工作,即为您下载合适的 Marionette 二进制文件机器(Linux、Mac 或 Windows)并导出正确系统属性的值.要使用此库,您需要将此依赖项包含到您的项目中:

    Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.0.1</version>
    </dependency>
    

    ... 然后在使用 WebDriver 之前在程序中执行这一行:

    ... and then execute this line in your program before using WebDriver:

    WebDriverManager.firefoxdriver().setup();
    

    使用 WebDriver 的 JUnit 4 测试用例的完整运行示例如下:

    A complete running example of a JUnit 4 test case using WebDriver could be as follows:

    public class FirefoxTest {
    
        protected WebDriver driver;
    
        @BeforeClass
        public static void setupClass() {
            WebDriverManager.firefoxdriver().setup();
        }
    
        @Before
        public void setupTest() {
            driver = new FirefoxDriver();
        }
    
        @After
        public void teardown() {
            if (driver != null) {
                driver.quit();
            }
        }
    
        @Test
        public void test() {
            // Your test code here
        }
    }
    

    考虑到 Marionette 将是未来的唯一选择(对于 WebDriver 3+ 和 Firefox 48+),但目前(编写时版本 0.9.0)不是很稳定.查看Marionette 路线图 了解更多详情.

    Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.

    更新

    Selenium WebDriver 2.53.1 已于 2016 年 6 月 30 日发布.FirefoxDriver 再次使用 Firefox 47.0.1 作为浏览器.

    Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver is working again with Firefox 47.0.1 as browser.

    这篇关于Selenium 2.53 不适用于 Firefox 47的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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