Python-Selenium3:在Firefox 45上打开浏览器

时间:2016-11-10 14:01:41

标签: python selenium firefox selenium-webdriver geckodriver

我使用python 2.7和使用selenium 3.0.1开发了一个自动测试工具。它在Firefox 49上工作正常。我需要它也能用于Firefox 45.我试过但是该工具发现问题打开浏览器。这段脚本如下:

from selenium import webdriver

downloadPath="path/downloads"
profile = webdriver.FirefoxProfile() 
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', downloadPath)
profile.set_preference('browser.helperApps.alwaysAsk.force', False)
profile.set_preference('browser.helperApps.neverAsk.openFile', 'application/x-targz, application/x-gzip, application/force-download')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/x-targz, application/x-gzip, application/force-download')
browser =  webdriver.Firefox(profile)

这个小程序在Firefox 49上很好用,但在Firefox 45中我收到了这个错误:

Traceback (most recent call last):
  File "path/test.py", line 10, in <module>
    browser =  webdriver.Firefox(profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.1-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.1-py2.7.egg/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. 

我在网上搜索,发现我必须安装geckodriver。 我从github下载了geckodriver:https://github.com/mozilla/geckodriver/releases我解压缩了tar.gz文件,并将其路径添加到PATH环境变量中:

export PATH=$PATH:/home/user/Downloads/geckodriver

但我得到了同样的错误。 有人知道如何修复这个错误吗?

0 个答案:

没有答案