如何正确设置Windows7以将Selenium与Firefox结合使用[带Python的TDD]?

我正在设置我的系统(Windows 7 Pro 64位,通过Anaconda使用Python 3.5),以通过硒使用Firefox,以遵循《用Python测试驱动开发》一书. Python不断抛出错误WebDriverException:’geckodriver.exe’可执行文件需要放在PAT...

我正在设置我的系统(Windows 7 Pro 64位,通过Anaconda使用Python 3.5),以通过硒使用Firefox,以遵循《用Python测试驱动开发》一书. Python不断抛出错误WebDriverException:’geckodriver.exe’可执行文件需要放在PATH中.即使我已将系统路径设置为指向geckodriver的文件夹(并重新启动了3次).

如果我将python / selenium指向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位),壁虎驱动程序,硒或其他完全错误有关.

解决方法:

如果您拥有64位计算机,请确保下载了GeckoDriver for win-64 bit.现在,将粘贴的下载的GeckoDriver可执行文件复制粘贴到“脚本”文件夹中(此文件夹位于系统中安装python的根文件夹中).现在在环境变量中设置python根文件夹和’Script’文件夹的路径

C:\..Python; //path of python root folder 
C:\..Python\Scripts; //path of python 'Script' folder

不要忘记重启系统以使更改生效&试试这个示例代码

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://google.com")

本文标题为:如何正确设置Windows7以将Selenium与Firefox结合使用[带Python的TDD]?

基础教程推荐