使用Selenium,Python脚本打开Firefox,而不是提供的URL

时间:2017-07-01 19:54:10

标签: python selenium firefox selenium-webdriver webdriver

问题

我正在关注文档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()

1 个答案:

答案 0 :(得分:0)

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

  • 将Firefox更新到最新版本
  • 更新了Selenium
  • bin文件夹
  • 中删除了不正确的geckodriver版本
  • 在App Store中更新了xcode
  • 使用brew install geckodriver将正确的版本导入bin文件夹
  • 已使用brew link
  • Ran script.py