Selenium 2.53在Firefox 47上不起作用

问题描述 投票:106回答:15

在将Firefox与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。

java selenium firefox selenium-webdriver selenium-firefoxdriver
15个回答
92
投票

很遗憾,Selenium WebDriver 2.53.0与Firefox 47.0不兼容。处理Firefox浏览器(FirefoxDriver)的WebDriver组件将停产。从3.0版开始,Selenium WebDriver将需要geckodriver二进制文件来管理Firefox浏览器。更多信息herehere

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

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

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

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

...,然后在使用WebDriver之前在程序中执行此行:

WebDriverManager.firefoxdriver().setup();

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

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

UPDATE

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


2
投票

您可以尝试使用此代码,


1
投票

我最终安装了另一个旧版本的Firefox(仅用于测试)以解决此问题,除了我的常规(安全,最新)最新Firefox安装。

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

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

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

1
投票

problem looked like in Wireshar k是什么>

只需加载2.53.1,一切都会正常。

截至2016年9月

[Firefox 48.0selenium==2.53.6正常运行,没有任何错误

要在Ubuntu 14.04上升级Firefox,[[仅

sudo apt-get update sudo apt-get upgrade firefox

1
投票

截至2016年9月


1
投票
在我看来,最好的解决方案是更新到Selenium 3.0.0,下载geckodriver.exe并使用Firefox 47或更高版本。

我将Firefox初始化更改为:

string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe"); string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe"); File.Copy(geckoPathTest, geckoPath); Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath); _firefoxDriver = new FirefoxDriver();


0
投票
我可以在Ubuntu 15上为我确定selenium 2.53.6firefox 44一起使用。

18
投票

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

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

10
投票

我有相同的问题,发现您需要切换驱动程序,因为support was dropped。代替使用Firefox Driver,您需要使用Marionette驱动程序来运行测试。我目前正在自己​​进行设置,如果您有我的工作示例,可以发布一些建议的步骤。

以下是我要在Mac上的Java环境上运行该文件的步骤(同样在我的Linux安装(Fedora,CentOS和Ubuntu)中也适用于我:]]

  1. releases page下载每晚可执行文件>
  2. 解压缩档案
  3. 为木偶创建目录(即mkdir -p /opt/marionette
  4. 将解压缩的可执行文件移动到您创建的目录中
  5. 更新您的$PATH以包含可执行文件(也可以根据需要编辑.bash_profile
  6. :bangbang:确保您chmod +x /opt/marionette/wires-x.x.x可执行,
  7. 在启动时,请确保使用以下代码(这是我在Mac上使用的代码)
  8. 速记

仍然无法正常工作,但至少现在启动了浏览器。需要弄清楚原因-现在看来我需要重写测试才能使其正常工作。

Java代码段

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

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

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

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

更多信息可以在git repo homebrew-firefox中找到。支撑smclernon以创建original cask

如果您使用的是Mac,请执行brew install geckodriver,然后关闭即可!

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

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));

覆盖FirefoxOptions以提供添加其他功能并设置Firefox配置文件的功能,因为selenium v53尚不提供该功能。

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

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

但是,我们试图将测试转换为使用Marionette,但由于驱动程序的实现未完成或有故障,目前暂时不可行。我建议人们此时将其Firefox降级。

根据:https://github.com/SeleniumHQ/selenium/issues/2110,现在已经有新的Selenium库出现了>

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

它对我来说适用于Firefox 47.0.1。

作为旁注,我可以通过运行./go //javascript/firefox-driver:webdriver:run从GitHub的master分支中仅构建webdriver.xpi

Firefox扩展-这给出了错误消息,但确实构建了build / javascript / firefox-driver / webdriver.xpi]文件,我可以重命名(以避免名称冲突)并成功使用FirefoxProfile.AddExtension方法加载。这是一个合理的解决方法,而无需重建整个Selenium库。

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

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

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

Firefox 47.0停止使用Webdriver。

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

您可以尝试使用此代码,

private WebDriver driver;
System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe");        
driver = new FirefoxDriver();

我已升级到硒3.0.0,而Firefox版本是49.0.1

您可以从https://github.com/mozilla/geckodriver/releases下载geckodriver.exe

请确保根据您的系统仅下载zip文件,geckodriver-v0.11.1-win64.zip文件或win32,并将其解压缩到文件夹中。

将文件夹的路径放在“您的驱动程序路径”中。不要忘记将geckodriver.exe放在路径中。

我最终安装了另一个旧版本的Firefox(仅用于测试)以解决此问题,除了我的常规(安全,最新)最新Firefox安装。

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

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

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

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

problem looked like in Wireshar k是什么>

只需加载2.53.1,一切都会正常。

截至2016年9月

[Firefox 48.0selenium==2.53.6正常运行,没有任何错误

要在Ubuntu 14.04上升级Firefox,[[仅

sudo apt-get update sudo apt-get upgrade firefox
在我看来,最好的解决方案是更新到Selenium 3.0.0,下载geckodriver.exe并使用Firefox 47或更高版本。

我将Firefox初始化更改为:

string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe"); string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe"); File.Copy(geckoPathTest, geckoPath); Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath); _firefoxDriver = new FirefoxDriver();

我可以在Ubuntu 15上为我确定selenium 2.53.6firefox 44一起使用。

6
投票

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


6
投票

如果您使用的是Mac,请执行brew install geckodriver,然后关闭即可!


3
投票

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


2
投票

根据:https://github.com/SeleniumHQ/selenium/issues/2110,现在已经有新的Selenium库出现了>

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


2
投票

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

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

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


2
投票

Firefox 47.0停止使用Webdriver。

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

© www.soinside.com 2019 - 2024. All rights reserved.