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 相关文章推荐
利用matplotlib+numpy绘制多种绘图的方法实例
May 03 Python
python3.5绘制随机漫步图
Aug 27 Python
Python Flask框架扩展操作示例
May 03 Python
PowerBI和Python关于数据分析的对比
Jul 11 Python
django 2.2和mysql使用的常见问题
Jul 18 Python
python爬虫 2019中国好声音评论爬取过程解析
Aug 26 Python
opencv resize图片为正方形尺寸的实现方法
Dec 26 Python
Python 解决火狐浏览器不弹出下载框直接下载的问题
Mar 09 Python
Python 多线程共享变量的实现示例
Apr 17 Python
Django封装交互接口代码
Jul 12 Python
pytorch 实现变分自动编码器的操作
May 24 Python
Python机器学习之底层实现KNN
Jun 20 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
php中 ob_start等函数截取标准输出的方法
2015/06/22 PHP
Yii视图CGridView实现操作按钮定义地址示例
2016/07/14 PHP
ThinkPHP 模板引擎使用详解
2017/05/07 PHP
phpstorm 配置xdebug的示例代码
2019/03/31 PHP
基于ThinkPHP5框架使用QueryList爬取并存入mysql数据库操作示例
2019/05/25 PHP
FF IE兼容性的修改小结
2009/09/02 Javascript
Jquery修改页面标题title其它JS失效的解决方法
2014/10/31 Javascript
jQuery+AJAX实现遮罩层登录验证界面(附源码)
2020/09/13 Javascript
node.js微信公众平台开发教程
2016/03/04 Javascript
jQuery插件编写步骤详解
2016/06/03 Javascript
浅谈javascript中的 “ &amp;&amp; ” 和 “ || ”
2017/02/02 Javascript
vue.js 左侧二级菜单显示与隐藏切换的实例代码
2017/05/23 Javascript
让div运动起来 js实现缓动效果
2017/07/06 Javascript
JavaScript函数式编程(Functional Programming)组合函数(Composition)用法分析
2019/05/22 Javascript
ionic+html5+API实现双击返回键退出应用
2019/09/17 Javascript
JS动态显示倒计时效果
2019/12/12 Javascript
JS实现表单中点击小眼睛显示隐藏密码框中的密码
2020/04/13 Javascript
详解如何修改 node_modules 里的文件
2020/05/22 Javascript
如何通过JS实现日历简单算法
2020/10/14 Javascript
[46:57]EG vs Winstrike 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
Python进度条实时显示处理进度的示例代码
2018/01/30 Python
Anaconda2下实现Python2.7和Python3.5的共存方法
2018/06/11 Python
python实现图片批量压缩程序
2018/07/23 Python
pandas的to_datetime时间转换使用及学习心得
2019/08/11 Python
Python基础之高级变量类型实例详解
2020/01/03 Python
Python3 Click模块的使用方法详解
2020/02/12 Python
pandas 强制类型转换 df.astype实例
2020/04/09 Python
欧舒丹澳洲版:L’OCCITANE
2017/07/17 全球购物
自动化工程专业个人应聘自荐信
2013/09/26 职场文书
复核员上岗演讲稿
2014/01/05 职场文书
2015年全民国防教育日活动总结
2015/03/23 职场文书
工作计划范文之财务管理
2019/08/09 职场文书
创业计划书之校园超市
2019/09/12 职场文书
MATLAB 全景图切割及盒图显示的实现步骤
2021/05/14 Python
聊聊pytorch测试的时候为何要加上model.eval()
2021/05/23 Python
拒绝盗图!教你怎么用python给图片加水印
2021/06/04 Python