我正在安装我的系统(Windows 7 Pro 64位,通过Anaconda使用Python 3.5),以通过selenium使用Firefox,以遵循《 用Python测试驱动开发 》一书 。WebDriverException: 'geckodriver.exe' executable needs to be in PATH.即使我将系统路径设置为指向geckodriver的文件夹(并重新启动了3次),Python仍然会引发错误。
WebDriverException: 'geckodriver.exe' executable needs to be in PATH.
如果我将python / selenium指向geckodriver.exe的确切位置,则会出现以下错误
geckodriver.exe
OSError: [WinError 216] This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher
在这一点上,我不确定错误版本%1是否与firefox是错误版本(我尝试过64位和32位),壁虎驱动程序,selenium或其他完全错误有关。
%1
wires.exe
Selenium3
pip install "selenium>=3.0.0"
geckodriver-v0.11.1-win64.zip
geckodriver-v0.11.1-win32.zip
version %1
C:\Users\YourUserName\Downloads\selenium_driver
C:\Program Files\Mozilla FirefoxESR
C:\Program Files (x86)\Mozilla FirefoxESR
如果将Windows PATH设置为C:\Users\YourUserName\Downloads\selenium_driver似乎无效(以便selenium可以找到geckdriver.exe),则可以在Python脚本中指定其目录,如下所示:
selenium
geckdriver.exe
from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary gecko = r'C:\Users\YourUserName\Downloads\selenium_driver\geckodriver.exe' ffox_binary = FirefoxBinary(r'C:\Program Files\Mozilla FirefoxESR\firefox.exe') #for 64 bit installation #ffox_binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla FirefoxESR\firefox.exe') #for 32 bit installation browser = webdriver.Firefox(firefox_binary=ffox_binary, executable_path=gecko) browser.get('http://localhost:8000')