【问题标题】:Using Selenium, Python script to open Firefox, not going to URL provided使用 Selenium,Python 脚本打开 Firefox,而不是提供的 URL
【发布时间】:2017-07-05 02:16:11
【问题描述】:

问题

我正在关注文档here 中列出的示例。基本上,只是试图让 Selenium 打开 Firefox,带我到一个站点,进行查询,然后关闭浏览器。

我遇到了一个问题,Selenium 会打开浏览器,但不会转到指定的网站。在其他情况下,我收到一个错误,我应该提到这个错误仅在升级 Selenium 后出现。

Traceback (most recent call last):
  File "script.py", line 4, in <module>
    browser = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
  • 我正在使用最新版本的 Firefox,54.0.1
  • 我正在使用 Python 版本2.7.11
  • 我有 Selenium 版本3.4.3

script.py

​​>
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')
assert 'Yahoo!' in browser.title

elem = browser.find_element_by_name('p')  # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)

browser.quit()

【问题讨论】:

  • 你下载geckodriver并设置它的路径。谷歌一下,你会发现很多帖子。

标签: python selenium firefox selenium-webdriver webdriver


【解决方案1】:

在这种情况下,这些是我为解决此问题而采取的步骤。

  • 已将 Firefox 更新到最新版本
  • 也更新了 Selenium
  • bin 文件夹中删除了错误版本的 geckodriver
  • 在 App Store 中更新了 xcode
  • 使用 brew install geckodriver 将正确的版本放入 bin 文件夹中
  • 使用brew link
  • 运行脚本.py

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-22
    • 2014-07-14
    • 1970-01-01
    • 2017-01-19
    • 2017-08-19
    • 2017-05-24
    • 2019-09-05
    • 2016-12-11
    相关资源
    最近更新 更多