【问题标题】:Selenium on Elementary OS not working with FirefoxElementary OS 上的 Selenium 不适用于 Firefox
【发布时间】:2017-02-25 18:49:46
【问题描述】:

我的系统上的 Selenium 有问题。由于某种原因,它不会启动 Firefox 浏览器窗口。

这是我已经完成的步骤。

  • 通过 pip 下载 Selenium
  • 已下载 Marionette (gecko) 驱动程序
  • 已将下载文件的目录添加到我的 PATH。

我仍然收到以下错误。

/usr/bin/python2.7 /home/keva161/PycharmProjects/selenium_test.py
Traceback (most recent call last):
  File "/home/keva161/PycharmProjects/selenium_test.py", line 21, in <module>
    driver = webdriver.Firefox(capabilities=caps)
  File "/home/keva161/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
    self.service.start()
  File "/home/keva161/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

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

我要运行的脚本是:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX

# Tell the Python bindings to use Marionette.
# This will not be necessary in the future,
# when Selenium will auto-detect what remote end
# it is talking to.
caps["marionette"] = True

# Path to Firefox DevEdition or Nightly.
# Firefox 47 (stable) is currently not supported,
# and may give you a suboptimal experience.
#
# On Mac OS you must point to the binary executable
# inside the application package, such as
# /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin
caps["binary"] = "/usr/bin/firefox"

driver = webdriver.Firefox(capabilities=caps)

driver = webdriver.Firefox()
driver.get('http://saucelabs.com/test/guinea-pig')
driver.quit()

我使用的是最新版本的 Firefox。

【问题讨论】:

    标签: python selenium firefox pycharm elementary


    【解决方案1】:

    PyCharm 会忽略您的 PYTHONPATH,而是根据您的项目配置构建它,因此您需要教它在哪里可以找到 gecko。您可以通过以下两种方式之一:

    • 配置你的解释器路径以包含壁虎的目录,见Interpreter paths
    • 将壁虎的目录添加为内容或源根目录(请参阅Content Root)并在项目的运行配置中选中相应的复选框(Add content roots to PYTHONPATHAdd source roots to PYTHONPATH),请参阅Run/Debug Configuration: Python

    【讨论】:

      猜你喜欢
      • 2015-02-03
      • 1970-01-01
      • 2016-11-25
      • 2016-12-06
      • 2016-12-12
      • 2017-03-05
      • 2017-03-19
      • 1970-01-01
      相关资源
      最近更新 更多