首页 文章

Selenium 2.53无法在Firefox 47上运行

提问于
浏览
105

使用带WebDriver的Firefox时出错 .

org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
  • Firefox版本:47.0

  • Selenium:2.53.0

  • Windows 10 64位

是否有人得到类似的问题或任何想法是什么解决方案?它适用于Chrome,但使用Firefox时,没有任何网址被加载 .

15 回答

  • 1

    这是一个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

    我可以在ubuntu 15上确认 selenium 2.53.6 对我有用 firefox 44 .

  • 6

    在我看来,最好的解决方案是更新到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();
    
  • 2

    这是problem looked like in Wireshar k

    只需加载2.53.1,每件事都可以 .

  • 17

    不幸的是,Selenium WebDriver 2.53.0与Firefox 47.0不兼容 . 处理Firefox浏览器的WebDriver组件( FirefoxDriver )将停止使用 . 从版本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.1.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 作为浏览器 .

  • 1

    如果有人想知道如何在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));
    

    覆盖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 .

  • 6

    尝试使用firefox 46.0.1 . 它最适合Selenium 2.53

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

    如果你在Mac上做 brew install geckodriver 而且你走了!

  • 2

    截至2016年9月

    Firefox 48.0selenium==2.53.6 工作正常,没有任何错误

    Ubuntu 14.04 only 上升级firefox

    sudo apt-get update
    sudo apt-get upgrade firefox
    
  • 3

    您可以尝试使用此代码,

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

    我升级到selenium 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放在路径中 .

  • 9

    我有同样的问题,发现你需要切换驱动程序,因为support was dropped . 您需要使用Marionette驱动程序来运行测试,而不是使用Firefox驱动程序 . 我目前正在进行设置,如果你有一个有效的例子,我可以发布一些建议的步骤 .

    以下是我在Mac上使用Java环境时所遵循的步骤(在我的Linux安装(Fedora,CentOS和Ubuntu)中为我工作):

    • releases page下载每晚可执行文件

    • 解压缩档案

    • 为Marionette创建一个目录(即 mkdir -p /opt/marionette

    • 将解压缩的可执行文件移动到您创建的目录中

    • 更新 $PATH 以包含可执行文件(如果需要,还可以编辑 .bash_profile

    • :bangbang:确保你 chmod +x /opt/marionette/wires-x.x.x 以便它是可执行的

    • 在发布时,请确保使用下面的代码(这是我在Mac上使用的代码)

    Quick Note

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

    Java Snippet

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

    根据: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中的主分支构建webdriver.xpi Firefox扩展 - 这给出了一条错误消息,但确实构建了build / javascript / firefox-driver / webdriver.xpi文件,我可以重命名(以避免名称冲突)并成功加载FirefoxProfile.AddExtension方法 . 这是一个合理的解决方法,无需重建整个Selenium库 .

  • 1

    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版本背后的主要原因 .

  • 0

    如果您使用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找到 . _1040161_用于创建original cask的道具 .

  • 2

    除了我的常规(安全,最新)最新的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 .

相关问题