【问题标题】:firefox with selenium not working带有硒的Firefox无法正常工作
【发布时间】:2016-08-18 23:05:10
【问题描述】:

所有,

最近,我为使用 firefox 和 selenium 的屏幕截图解决方案设置了一个新的 ubuntu 服务器(版本 14.04.3)。虽然从firefox v47开始有很多关于这个话题的讨论,但似乎都无法解决我的问题。

我的python脚本如下:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "/usr/bin/firefox"

browser = webdriver.Firefox(capabilities=caps)
browser.set_window_size(1200, 2400)

对于我的开发服务器,我有 firefox v47.0.1 和 selenium 2.53.5,并且代码有效。 但是在我的新系统中,一开始我有 firefox 48 和 selenium 2.53.6,我得到了错误:

  browser = webdriver.Firefox(capabilities=caps)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 65, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
WebDriverException: Message: 'wires' executable needs to be in PATH. 

我尝试将 firefox 二进制文件添加到 PATH:

export PATH=$PATH:/usr/bin/firefox

在这之后,我得到了新的错误:

browser = webdriver.Firefox(capabilities=caps)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 65, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 20] Not a directory

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7fe3183edf50>> ignored

here 的帖子提到 v48 应该可以解决这个问题,但似乎不是。然后我将 firefox 降级到 v47.0.1,但仍然出现相同的错误。我检查了 v2.53.6 和 v2.53.5 中的 selenium 代码,无法真正确定问题所在。然后我将 selenium 卸载到 v2.53.5。但仍然得到同样的错误。我认为我的与带有 selenium 的 firefox 相关的设置可能有问题,但无法进一步调试。

有人可以帮忙吗? 非常感谢

志宏

【问题讨论】:

    标签: selenium firefox


    【解决方案1】:

    好吧,我也遇到了同样的问题,我刚刚切换到 Chrome 网络驱动程序...

    但如果您想继续使用 Firefox,请尝试将 selenium 升级到 3.0.0。

    【讨论】:

    • 谢谢你的回答,不知道有selenium 3.0发布了,我试试看,否则,也会移到chrome
    • 您可能还想为 firefox 47+ 使用 gecko 驱动程序github.com/mozilla/geckodriver/releases
    • RadekE,谢谢,是的,我已经在使用 gecko 驱动程序了。不同之处在于,使用 47+ 和 selenium 2.56,您修补木偶以解决问题。如果使用 selenium 3.0(我根据您的建议尝试过),则需要安装 gecko 驱动程序。
    【解决方案2】:

    知宏你做的一切都正确。 昨天将 Firefox 升级到 v48 后,我今天遇到了同样的问题。最好的解决方案是降级到与 Selenium 完全兼容的 47.0.1(可以从 here 下载)(2.35.1 for Java 或 2.35.0对于 Python)

    祝你好运!

    【讨论】:

    • 感谢您的回复。我已经尝试将 Firefox 降级到 47.0.1,得到了同样的错误。运气不好,将 selenium 降级到 2.35.0 后,我收到了其他错误:WebDriverException:消息:'无法加载配置文件。 ...快速检查,这与硒中的一个旧错误有关。所以还没解决问题。
    • 该死,倒霉!令我困惑的是,根据您的帖子,这对您来说事先工作得很好(即 ​​v47.0.1 Firefox 和 Selenium 的 2.35.5)-但是您已经尝试过了……当然,您应该能够恢复到旧的情况。新系统有什么变化?只有事实可能是您的 Firefox bin 文件夹可能位于您的开发机器的其他位置,或者您可能没有足够的权限来访问该文件夹..问题?您的旧设置在您的 Ubuntu 服务器上运行良好吗?如果是的话,我认为更多的是指向正确的道路..
    • 在我的开发服务器中工作的 selenium 是 2.53.5 版。不是 2.35.5。新系统(不是很新,但生产服务器运行脚本很少),之前没有安装selenium和firefox,firefox bin set和我开发的一样,我能看到的唯一区别是系统版本,新的是14.04 .3,我的本地是14.04.05,我会更新服务器看看会发生什么
    猜你喜欢
    • 2021-11-20
    • 2017-05-12
    • 2015-10-15
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 2016-11-13
    • 2018-11-03
    • 2020-05-17
    相关资源
    最近更新 更多