Java Selenium 2.53 不适用于 Firefox 47

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37693106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:33:49  来源:igfitidea点击:

Selenium 2.53 not working on Firefox 47

javaseleniumfirefoxselenium-webdriverselenium-firefoxdriver

提问by veena k

I am getting error while using Firefox with WebDriver.

使用带有 WebDriver 的 Firefox 时出现错误。

org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
  • Firefox version:47.0
  • Selenium:2.53.0
  • Windows 10 64 bit
  • 火狐版本:47.0
  • 硒:2.53.0
  • 视窗 10 64 位

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.

有没有人遇到类似的问题或知道解决方案是什么?它在 Chrome 上运行良好,但在 Firefox 中没有任何 URL 被加载。

回答by Mahbub Rahman

Try using firefox 46.0.1. It best matches with Selenium 2.53

尝试使用 Firefox 46.0.1。它与 Selenium 2.53 最匹配

https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/

回答by el n00b

I had the same issue and found out that you need to switch drivers because support was dropped. Instead of using the Firefox Driver, you need to use the MarionetteDriver in order to run your tests. I am currently working through the setup myself and can post some suggested steps if you'd like when I have a working example.

我遇到了同样的问题,发现您需要切换驱动程序,因为 支持已被删除。您需要使用MarionetteDriver 来运行测试,而不是使用Firefox Driver。我目前正在自己​​完成设置,如果您愿意,我可以在我有一个工作示例时发布一些建议的步骤。

Here are the steps I followed to get this working on my Java environment on Mac (worked for me in my Linux installations (Fedora, CentOS and Ubuntu) as well):

以下是我在 Mac 上的 Java 环境中运行的步骤(也适用于我的 Linux 安装(Fedora、CentOS 和 Ubuntu)):

  1. Download the nightly executable from the releases page
  2. Unpack the archive
  3. Create a directory for Marionette (i.e., mkdir -p /opt/marionette)
  4. Move the unpacked executable file to the directory you made
  5. Update your $PATHto include the executable (also, edit your .bash_profileif you want)
  6. :bangbang: Make sure you chmod +x /opt/marionette/wires-x.x.xso that it is executable
  7. In your launch, make sure you use the following code below (it is what I used on Mac)
  1. 发布页面下载每晚可执行文件
  2. 解压存档
  3. 为 Marionette 创建一个目录(即mkdir -p /opt/marionette
  4. 将解压后的可执行文件移动到你制作的目录中
  5. 更新您$PATH以包含可执行文件(也可以.bash_profile根据需要编辑您的)
  6. :bangbang: 确保chmod +x /opt/marionette/wires-x.x.x它是可执行的
  7. 在启动时,请确保使用以下代码(这是我在 Mac 上使用的代码)

Quick Note

快速笔记

Still not working as expected, but at least gets the browser launched now. Need to figure out why - right now it looks like I need to rewrite my tests to get it to work.

仍然没有按预期工作,但至少现在启动了浏览器。需要找出原因 - 现在看起来我需要重写我的测试才能让它工作。

Java Snippet

Java 代码段

WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");

回答by Boni García

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 geckodriverbinary to manage Firefox browsers. More info hereand here.

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

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 geckodriveras of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driveras a system property in your Java code:

因此,为了使用Firefox 47.0浏览器作为硒webdriver的2.53.0,你需要下载Firefox的驱动程序(称为一个二进制文件geckodriver为0.8.0版本,以及以前wires)和绝对路径导出到变量webdriver.gecko.driver作为Java 代码中的系统属性:

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

Luckily, the library WebDriverManagercan 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:

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

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

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

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

WebDriverManager.firefoxdriver().setup();

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

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

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

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 roadmapfor further details.

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

UPDATE

更新

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

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

回答by Steven

In case anyone is wondering how to use Marionette in C#.

如果有人想知道如何在 C# 中使用 Marionette。

FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
    service,
    option,
    TimeSpan.FromSeconds(30));

Overriding FirefoxOptions to provide the function to add additional capability and set Firefox profile because selenium v53doesn't provide that function yet.

覆盖 FirefoxOptions 以提供添加附加功能和设置 Firefox 配置文件的功能,因为selenium v​​53尚未提供该功能。

public class FirefoxProfileOptions : FirefoxOptions
{
    private DesiredCapabilities _capabilities;

    public FirefoxProfileOptions()
        : base()
    {
        _capabilities = DesiredCapabilities.Firefox();
        _capabilities.SetCapability("marionette", this.IsMarionette);
    }

    public FirefoxProfileOptions(FirefoxProfile profile)
        : this()
    {
        _capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
    }

    public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
    {
        _capabilities.SetCapability(capabilityName, capabilityValue);
    }

    public override ICapabilities ToCapabilities()
    {
        return _capabilities;
    }
}

Note: Launching with profile doesn't work with FF 47, it works with FF 50 Nightly.

注意:使用配置文件启动不适用于 FF 47,它适用于 FF 50 Nightly。

However, we tried to convert our test to use Marionette, and it's just not viable at the moment because the implementation of the driver is either not completed or buggy. I'd suggest people downgrade their Firefox at this moment.

然而,我们试图将我们的测试转换为使用 Marionette,但目前它不可行,因为驱动程序的实现要么没有完成,要么有错误。我建议人们此时降级他们的 Firefox。

回答by Supra

Its a FF47 issue https://github.com/SeleniumHQ/selenium/issues/2110

它是 FF47 问题 https://github.com/SeleniumHQ/selenium/issues/2110

Please downgrade to FF 46 or below (or try out FF48 developer https://developer.mozilla.org/en-US/Firefox/Releases/48)

请降级到 FF 46 或以下(或尝试 FF48 开发者https://developer.mozilla.org/en-US/Firefox/Releases/48

Instructions on how to downgrade: https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/Or if you are on Mac, as suggested by someone else in this thread use brew.

有关如何降级的说明:https: //www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/或者如果您是在 Mac 上,正如本线程中其他人所建议的那样,使用 brew。

回答by avandeursen

I eventually installed an additional old version of Firefox (used for testing only) to resolve this, besides my regular (secure, up to date) latest Firefox installation.

除了我常规(安全、最新)的最新 Firefox 安装之外,我最终安装了一个额外的旧版本 Firefox(仅用于测试)来解决这个问题。

This requires webdriver to know where it can find the Firefox binary, which can be set through the webdriver.firefox.binproperty.

这需要 webdriver 知道它在哪里可以找到 Firefox 二进制文件,这可以通过webdriver.firefox.bin属性设置。

What worked for me (mac, maven, /tmp/ff46as installation folder) is:

对我有用的(mac,maven,/tmp/ff46作为安装文件夹)是:

mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify

To install an old version of Firefox in a dedicated folder, create the folder, open Finder in that folder, download the Firefox dmg, and drag it to that Finder.

要在专用文件夹中安装旧版本的 Firefox,请创建该文件夹,在该文件夹中打开 Finder,下载 Firefox dmg,然后将其拖到该 Finder。

回答by Dan Caddigan

If you're on OSX using Homebrew, you can install old Firefox versions via brew cask:

如果你在 OSX 上使用 Homebrew,你可以通过 brew cask 安装旧的 Firefox 版本:

brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want

After installing, you'll just need to rename your FF executable in the Applications directory to "Firefox".

安装后,您只需将 Applications 目录中的 FF 可执行文件重命名为“Firefox”。

More info can be found at the git repo homebrew-firefox. Props to smclernonfor creating the original cask.

更多信息可以在 git repo homebrew-firefox 找到smclernon用于创建原始木桶的道具。

回答by Otto G

New Selenium libraries are now out, according to: https://github.com/SeleniumHQ/selenium/issues/2110

新的 Selenium 库现已发布,根据:https: //github.com/SeleniumHQ/selenium/issues/2110

The download page http://www.seleniumhq.org/download/seems not to be updated just yet, but by adding 1 to the minor version in the link, I could download the C# version: http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip

下载页面http://www.seleniumhq.org/download/似乎还没有更新,但是通过在链接的次要版本中添加 1,我可以下载 C# 版本:http://selenium-release。 storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip

It works for me with Firefox 47.0.1.

它适用于 Firefox 47.0.1。

As a side note, I was able build just the webdriver.xpiFirefox extension from the master branch in GitHub, by running ./go //javascript/firefox-driver:webdriver:run– which gave an error message but did build the build/javascript/firefox-driver/webdriver.xpifile, which I could rename (to avoid a name clash) and successfully load with the FirefoxProfile.AddExtension method. That was a reasonable workaround without having to rebuild the entire Selenium library.

作为旁注,我可以通过运行从 GitHub 的 master 分支构建webdriver.xpiFirefox 扩展./go //javascript/firefox-driver:webdriver:run- 这给出了一条错误消息,但确实构建了build/javascript/firefox-driver/webdriver.xpi文件,我可以重命名(以避免名称冲突)并成功加载 FirefoxProfile.AddExtension 方法。这是一种合理的解决方法,无需重建整个 Selenium 库。

回答by user7610

Firefox 47.0 stopped working with Webdriver.

Firefox 47.0 停止使用 Webdriver。

Easiest solution is to switch to Firefox 47.0.1 and Webdriver 2.53.1. This combination again works. In fact, restoring Webdriver compatibility was the main reason behind the 47.0.1 release, according to https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/.

最简单的解决方案是切换到 Firefox 47.0.1 和 Webdriver 2.53.1。这种组合再次起作用。事实上,根据https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/的说法,恢复 Webdriver 兼容性是 47.0.1 版本背后的主要原因。

回答by John Peters

Here's what the problem looked like in Wireshark

这是Wireshark 中 的问题

Just load up 2.53.1 and every thing will work.

只需加载 2.53.1,一切都会工作。