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的Tornado框架异步编程入门实例
Apr 24 Python
python 简单备份文件脚本v1.0的实例
Nov 06 Python
Python语言描述机器学习之Logistic回归算法
Dec 21 Python
python中logging包的使用总结
Feb 28 Python
用tensorflow搭建CNN的方法
Mar 05 Python
Python功能点实现:函数级/代码块级计时器
Jan 02 Python
python sklearn常用分类算法模型的调用
Oct 16 Python
Python中低维数组填充高维数组的实现
Dec 02 Python
新手入门学习python Numpy基础操作
Mar 02 Python
PyTorch中的C++扩展实现
Apr 02 Python
python如何变换环境
Jul 21 Python
Python入门之基础语法详解
May 11 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
漫荒推荐:画风超赞的国风漫画推荐 超长假期不无聊
2020/03/08 国漫
php+ajax简单实现全选删除的方法
2016/12/06 PHP
Django 中 cookie的使用
2017/08/17 PHP
php自动加载代码实例详解
2021/02/26 PHP
Js实现滚动变色的文字效果
2014/06/16 Javascript
javascript冒泡排序小结
2016/04/10 Javascript
基于javascript实现的购物商城商品倒计时实例
2016/12/11 Javascript
AngularJs篇:使用AngularJs打造一个简易权限系统的实现代码
2016/12/26 Javascript
javascript 中iframe高度自适应(同域)实例详解
2017/05/16 Javascript
关于webpack代码拆分的解析
2017/07/20 Javascript
javascript实现QQ空间相册展示源码
2017/12/12 Javascript
详解vue+webpack+express中间件接口使用
2018/07/17 Javascript
利用d3.js力导布局绘制资源拓扑图实例教程
2019/01/08 Javascript
在vue中根据光标的显示与消失实现下拉列表
2019/09/29 Javascript
Javascript异步编程async实现过程详解
2020/04/02 Javascript
python2.7删除文件夹和删除文件代码实例
2013/12/18 Python
利用Python和OpenCV库将URL转换为OpenCV格式的方法
2015/03/27 Python
利用Python实现简单的相似图片搜索的教程
2015/04/23 Python
Python实现将MySQL数据库表中的数据导出生成csv格式文件的方法
2018/01/11 Python
python调用百度REST API实现语音识别
2018/08/30 Python
python机器学习库scikit-learn:SVR的基本应用
2019/06/26 Python
python中的线程threading.Thread()使用详解
2019/12/17 Python
Python自带的IDE在哪里
2020/07/01 Python
三星英国官网:Samsung英国
2018/09/25 全球购物
欧洲著名的二手奢侈品网站:Vestiaire Collective
2020/03/07 全球购物
指针和引用有什么区别
2013/01/13 面试题
传统软件工程与面向对象的软件工程有什么区别
2012/05/31 面试题
社区敬老月活动实施方案
2014/02/17 职场文书
理财投资建议书
2014/03/12 职场文书
房产代理公证处委托书
2014/04/04 职场文书
《诚实与信任》教学反思
2014/04/10 职场文书
书香校园建设方案
2014/05/02 职场文书
关于对大人不礼貌的检讨书
2014/09/29 职场文书
高中化学教学反思
2016/02/22 职场文书
导游词之海南天涯海角
2019/12/05 职场文书
疑《守望先锋2》A测截图泄露 或将推出新模式、新界面
2022/04/03 其他游戏