Python3+selenium配置常见报错解决方案


Posted in Python onAugust 28, 2020

第一个坑:'geckodriver' executable needs to be in PATH

1.如果启动浏览器过程中报如下错误

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
self.service.start()
File "D:\test\python3\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.

2.这个是因为最新的selenium3.0启动firefox需要geckodriver.exe这个驱动文件。

3.下载之后,配置到环境变量path下(可以直接放python根目录)

第二坑:Expected browser binary location, but unable to find binary in default location

1.如果启动浏览器过程中报如下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)

File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.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.

2.这个是因为firefox.exe这个文件也需要配置到环境变量path下。

3.这个路径就是安装完firefox后,找到firefox.exe这个文件的地址,加到path下。

第三坑:Unsupported Marionette protocol version 2, required 3

1.如果启动浏览器过程中出现如下错误

Traceback (most recent call last):
File "<stdin>", line 1, in <module>

File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3

2.这个错误原因是firefox版本过低了,最新的selenium3.0版本支持firefox47以上的版本,升级版本就可以了

第四坑:WebDriverException: Message: newSession

1.Traceback (most recent call last):

File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 170, in init
keep_alive=True)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 156, in init
self.start_session(capabilities, browser_profile)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 314, in execute
self.error_handler.check_response(response)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\errorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession

2.下载最新的geckodriver.exe 然后把它放到python的安装目录下

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python的Flask框架中SQLAlchemy使用时的乱码问题解决
Nov 07 Python
基于numpy.random.randn()与rand()的区别详解
Apr 17 Python
python sys,os,time模块的使用(包括时间格式的各种转换)
Apr 27 Python
django反向解析和正向解析的方式
Jun 05 Python
Python读取Excel表格,并同时画折线图和柱状图的方法
Oct 14 Python
浅谈Python3中strip()、lstrip()、rstrip()用法详解
Apr 29 Python
Python中print和return的作用及区别解析
May 05 Python
python向字符串中添加元素的实例方法
Jun 28 Python
如何基于python生成list的所有的子集
Nov 11 Python
解决Python图形界面中设置尺寸的问题
Mar 05 Python
利用pyecharts读取csv并进行数据统计可视化的实现
Apr 17 Python
Python 实现定积分与二重定积分的操作
May 26 Python
Python 中如何写注释
Aug 28 #Python
Python操作Word批量生成合同的实现示例
Aug 28 #Python
Python接口自动化测试的实现
Aug 28 #Python
解决python和pycharm安装gmpy2 出现ERROR的问题
Aug 28 #Python
Python自动登录QQ的实现示例
Aug 28 #Python
python opencv pytesseract 验证码识别的实现
Aug 28 #Python
简单的命令查看安装的python版本号
Aug 28 #Python
You might like
一个简单的自动发送邮件系统(一)
2006/10/09 PHP
Windows PHP5和Apache的安装与配置
2009/06/08 PHP
PHP输出一个等腰三角形的方法
2015/05/12 PHP
PHP实现C#山寨ArrayList的方法
2015/07/16 PHP
Yii2中YiiBase自动加载类、引用文件方法分析(autoload)
2016/07/25 PHP
PHP7 新特性详细介绍
2016/09/06 PHP
jQuery 事件队列调整方法
2009/09/18 Javascript
drag-and-drop实现图片浏览器预览
2015/08/06 Javascript
jQuery实现Email邮箱地址自动补全功能代码
2015/11/03 Javascript
js遍历map javaScript遍历map的简单实现
2016/08/26 Javascript
微信小程序购物商城系统开发系列-工具篇的介绍
2016/11/21 Javascript
浅析jsopn跨域请求原理及cors(跨域资源共享)的完美解决方法
2017/02/06 Javascript
jQuery设置图片等比例缩小的方法
2017/04/29 jQuery
利用Ionic2 + angular4实现一个地区选择组件
2017/07/27 Javascript
用node-webkit把web应用打包成桌面应用(windows环境)
2018/02/01 Javascript
Layui实现主窗口和Iframe层参数传递
2019/11/14 Javascript
js判断在哪个浏览器打开项目的方法
2020/01/21 Javascript
antd的select下拉框因为数据量太大造成卡顿的解决方式
2020/10/31 Javascript
[06:37]2014DOTA2国际邀请赛 昔日王者渴望重回巅峰
2014/07/12 DOTA
[00:10]DOTA2全国高校联赛 以DOTA2会友
2018/05/30 DOTA
Python random模块常用方法
2014/11/03 Python
python mysql中in参数化说明
2020/06/05 Python
python实现斗地主分牌洗牌
2020/06/22 Python
基于Python实现天天酷跑功能
2021/01/06 Python
TheFork葡萄牙:欧洲领先的在线餐厅预订平台
2019/05/27 全球购物
电气技术员岗位职责
2013/11/19 职场文书
企划专员岗位职责
2013/12/09 职场文书
法人代表委托书
2014/04/04 职场文书
医学专业毕业生推荐信
2014/07/12 职场文书
购房协议书范本(无房产证)
2014/10/07 职场文书
医生学习党的群众路线教育实践活动心得体会
2014/11/03 职场文书
2014年小学德育工作总结
2014/12/05 职场文书
2014年妇女工作总结
2014/12/06 职场文书
见义勇为事迹材料
2014/12/24 职场文书
写给纪委的违纪检讨书
2015/05/05 职场文书
行政复议答复书
2015/07/01 职场文书