搭建测试环境中出现的问题总结
配置错误
在搭建测试中出现如下代码错误:selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
此时的版本执行需要驱动:geckodriver,解压放到D:\Python27中,然后在路径中会出现图2 的一些文件。最后配置图3 关于geckodriver驱动的路径。
图1 图2 图3
代码错误
在搭建测试中出现:mon.exceptions.WebDriverException:Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line。
方案一:这时我们需要指定Firefox浏览器程序路径。
binary = FirefoxBinary('D:\\Firefox\\Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
注:提示找不到"firefoxBinary"可以通过下面语句导入from selenium.webdriver.firefox.firefox_binary import FirefoxBinary这样就能正常使用了。
方案二:
将firefox的安装路径,直接增加到 python35\Lib\site-packages\selenium\webdriver\firefox目录下的 firefox_binary.py文件中,如下图所示,然后driver = webdriver.Firefox()调用.
安装SetupTools出现问题
出现此错误Python version 2.7 required, which was not found in the registry
新一个register.py 文件,把下面代码贴进去,保存(G盘)
# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy()
在系统命令中输入以下命令:
当显示“python 2.7 is already registered”,再安装setuptools的时候,就能自动识别出来python2.7了。win7是 64的原因,在安装python(32位)时,如果选择只为当前用户,以上问题是不会出现的,如果选择所有用户,那就用上面的方法解决吧。