python selenium 3.0 - 默认位置安装的Firefox 47.0.1未被识别。 (geckodriver) [英] python selenium 3.0 - Firefox 47.0.1 installed in default location is not identified. (geckodriver)

查看:569
本文介绍了python selenium 3.0 - 默认位置安装的Firefox 47.0.1未被识别。 (geckodriver)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的环境:


  1. 操作系统:Windows 10 - 64(家庭版)

  2. 浏览器:Firefox 47.0.1(32位)
  3. Python:2.7.10.12(64位)
  4. selenium:3.0.1
  5. >
  6. Geckodriver:geckodriver-v0.11.1-win64.zip

Firefox安装在<$ c $ geckodriver.exe被放置在中,这个文件位于 \\ Program Files(x86)\ Mozilla Firefox C:\Python27\Scripts location。



以下是我的python代码:

 来自selenium import webdriver 

driver = webdriver.Firefox()
driver.get(http://www.python.org )

其中给出以下错误:

  Traceback(最近一次调用的最后一个):
在< module>文件中的examples1.py,第5行。
driver = webdriver.Firefox()
文件C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py,第152行,在__init__
keep_alive = True)
文件C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py,行92,在__init__
self.start_session(desired_capabilities,browser_profile)
文件C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py,第179行,在start_session
response = self.execute(Command.NEW_SESSION,功能)
文件C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py 236行,执行
self.error_handler.check_response(response)
文件C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler .py,第192行,在check_response
中引发exception_class (message,screen,stacktrace)
selenium.common.exceptions.WebDriverException:消息:期望的浏览器二进制位置,但无法在默认位置找到二进制文件,没有提供moz:firefoxOptions.binary功能,并且没有二进制标志在命令行中设置

我的问题是虽然firefox安装在默认位置,但webdriver不能能够找到它并抛出错误。

注意:当我明确指定Firefox二进制位置如下时,它正在工作。

  binary = FirefoxBinary(r'C:\Program Files(x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox (firefox_binary = binary)


解决方案

重启我的机器解决了这个问题。(如果你把 geckodriver.exe 保存在 PATH 地点。



不知道这是否是真正的问题需要解决的,但其中的一个变量。






geckodriver.exe和Firefox版本的小背景支持:

来自 geckodriver github页面:

  Firefox 47显式不支持

如果您想使用 Firefox 47.0.1 版本,请使用 Firefox驱动程序但不要 geckodriver


  1. 如果使用硒2.53,您不需要做任何其他的事情(不需要设置 geckodriver as selenium 2.53 使用 Firefox驱动程序由 default )。

  2. 在Selenium 3.0中,我们必须设置 geckodriver 路径(如 geckodriver Selenium 3.0 Firefox 的默认 code> System.setProperty 并将 marionette 设置为 false ,所以 geckodriver 功能将被禁用,并使用默认的Firefox驱动程序。 代码:

      System.setProperty(webdriver.gecko.driver,path / to / geckodriver.exe ); 
    DesiredCapabilities d = new DesiredCapabilities();
    d.setCapability(marionette,false); //禁用木偶,默认true
    WebDriver driver = new FirefoxDriver(d);

    参考文献:


    1. https://github.com/mozilla/geckodriver#supported-firefoxen

    2. https://github.com/mozilla/geckodriver / issues / 224

    3. https://stackoverflow.com/a/40658421 / 2575259


    Following is my environment:

    1. OS : Windows 10 - 64 (Home edition)
    2. Browser : Firefox 47.0.1 (32 bit)
    3. Python : 2.7.10.12 (64 bit)
    4. selenium : 3.0.1
    5. Geckodriver: geckodriver-v0.11.1-win64.zip

    Firefox is installed in C:\Program Files (x86)\Mozilla Firefox.

    geckodriver.exe is placed in C:\Python27\Scripts location.

    Following is my python code:

    from selenium import webdriver
    
    driver = webdriver.Firefox()
    driver.get("http://www.python.org")
    

    Which gives the following error:

    Traceback (most recent call last):
      File "examples1.py", line 5, in <module>
        driver = webdriver.Firefox()
      File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
        keep_alive=True)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
        self.start_session(desired_capabilities, browser_profile)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
        response = self.execute(Command.NEW_SESSION, capabilities)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
        self.error_handler.check_response(response)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
    

    My question is that though firefox is installed in default location, webdriver could not be able to find it and throws the error.

    Note: when I explicitly specify the Firefox binary location as follows, it is working.

    binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    driver = webdriver.Firefox(firefox_binary=binary)
    

    解决方案

    Restarting my machine solved the issue. (May be required if you keep the geckodriver.exe in one of the PATH locations.

    Not sure if it was the real issue that needs to be solved, but one of the variable.


    Little Background to geckodriver.exe and Firefox version support:

    From geckodriver github page:

    Firefox 47 is explicitly not supported
    

    So, If you want to use Firefox 47.0.1 version, use Firefox driver but not geckodriver.

    1. In case of selenium 2.53, you don't need to do any additional things (no need to setup geckodriver as selenium 2.53 uses Firefox driver by default).
    2. In Selenium 3.0, we must set geckodriver path (as geckodriver is the default driver for Firefox in Selenium 3.0) using System.setProperty and set marionette to false, so geckodriver capabilities will be disabled and default Firefox driver is used.

    example code:

    System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
    DesiredCapabilities d = new DesiredCapabilities();
    d.setCapability("marionette", false);  // to disable marionette, by default true
    WebDriver driver = new FirefoxDriver(d);
    

    References:

    1. https://github.com/mozilla/geckodriver#supported-firefoxen
    2. https://github.com/mozilla/geckodriver/issues/224
    3. https://stackoverflow.com/a/40658421/2575259

    这篇关于python selenium 3.0 - 默认位置安装的Firefox 47.0.1未被识别。 (geckodriver)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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