python Selenium2.0模块使用中报错的解决办法
2017-04-24 10:09
781 查看
使用场景:windows环境下利用python3.5.0+Selenium3.4.0+Firefox53.0进行自动化测试
问题:执行自动化脚本报错:
Traceback (most recent call last):
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/python/代码/baidu.py", line 7, in <module>
driver=webdriver.Firefox()
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
解决方法:
从Selenium3.x开始,webdriver/firefox/webdriver.py的_init_中,executable_path=“geckodriver”。
但是Selenium2.x的executable_path="wires"
firefox 47及以上版本需要下载第三方driver,也就是geckodriver。
在https://github.com/mozilla/geckodriver/releases中下载指定操作系统的版本。把下载的压缩包解压后,将解压的路径加入到环境变量path中,重启python即可!
备注:安装三大浏览器驱动driver
1.chromedriver 下载地址:http://www.seleniumhq.org/download/
2.Firefox的驱动geckodriver 下载地址:http://www.seleniumhq.org/download/
3.IE的驱动IEdriver 下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/
注意:下载解压后,将chromedriver.exe , geckodriver.exe , Iedriver.exe发到Python的安装目录,例如 D:\python 。 然后再将Python的安装目录添加到系统环境变量的Path下面。
启动三大浏览器
启动谷歌浏览器
启动IE浏览器
问题:执行自动化脚本报错:
Traceback (most recent call last):
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/python/代码/baidu.py", line 7, in <module>
driver=webdriver.Firefox()
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\Users\Administrator.USER-20160704ZY\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
解决方法:
从Selenium3.x开始,webdriver/firefox/webdriver.py的_init_中,executable_path=“geckodriver”。
但是Selenium2.x的executable_path="wires"
firefox 47及以上版本需要下载第三方driver,也就是geckodriver。
在https://github.com/mozilla/geckodriver/releases中下载指定操作系统的版本。把下载的压缩包解压后,将解压的路径加入到环境变量path中,重启python即可!
备注:安装三大浏览器驱动driver
1.chromedriver 下载地址:http://www.seleniumhq.org/download/
2.Firefox的驱动geckodriver 下载地址:http://www.seleniumhq.org/download/
3.IE的驱动IEdriver 下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/
注意:下载解压后,将chromedriver.exe , geckodriver.exe , Iedriver.exe发到Python的安装目录,例如 D:\python 。 然后再将Python的安装目录添加到系统环境变量的Path下面。
启动三大浏览器
启动谷歌浏览器
from selenium import webdriver browser = webdriver.Chrome() browser.get('http://www.baidu.com/') 启动火狐浏览器
from selenium import webdriver browser = webdriver.Firefox() browser.get('http://www.baidu.com/')
启动IE浏览器
from selenium import webdriver browser = webdriver.Ie() browser.get('http://www.baidu.com/')
相关文章推荐
- Python3 使用 logging 模块输出日志中的中文乱码解决办法
- python selenium模块使用出错解决,Message: 'geckodriver' executable needs to be in PATH
- Python基础 —— 使用 pickle 模块存储数据报错的解决办法
- python2.7使用logging模块记日志,中文记入后乱码解决办法
- python selenium模块使用出错解决,Message: 'geckodriver' executable needs to be in PATH
- 基于Python3.6使用Django框架连接mysql数据库的驱动模块安装解决办法
- 在 python 中使用 Selenium 报错self.capabilities = response['value'] KeyError: 'value'的解决办法
- Flash cs 3 开发flash lite 2.0 使用软键中的错误及解决办法
- 在ie上使用xpath时selenium运行缓慢的解决办法
- 使用Gevent程序正常运行出现这个异常KeyError(155880780,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored解决办法
- centos下装完python2.7无法使用yum的解决办法
- Python 使用 UTF-8 编码,python代码中包含中文时执行脚本错误的解决办法。
- Flash图表组件——使用Open Flash Chart 2.0的一些问题及解决办法
- 升级python版本导致Django无法使用的解决办法
- python2.7 使用super关键词 报错 TypeError: must be type, not classobj 解决办法
- python内置的urllib模块不支持https协议的解决办法
- Selenium-解决使用Webdrive打开Firefox不含有插件的问题(python)
- python2.6使用mysql包出现的一些问题以及解决办法
- python升级导致yum命令无法使用的解决办法
- 使用Asp.net MVC 2.0 +.NET 4.0 出现 “从客户端 ... 中检测到有潜在危险的 Request.Form 值”错误的解决办法