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除法运算小技巧
Apr 05 Python
使用Python多线程爬虫爬取电影天堂资源
Sep 23 Python
Python中类型检查的详细介绍
Feb 13 Python
python链接oracle数据库以及数据库的增删改查实例
Jan 30 Python
浅谈Python脚本开头及导包注释自动添加方法
Oct 27 Python
python实现本地图片转存并重命名的示例代码
Oct 27 Python
python傅里叶变换FFT绘制频谱图
Jul 19 Python
使用python实现对元素的长截图功能
Nov 14 Python
分享unittest单元测试框架中几种常用的用例加载方法
Dec 02 Python
Pytorch1.5.1版本安装的方法步骤
Dec 31 Python
使用pandas或numpy处理数据中的空值(np.isnan()/pd.isnull())
May 14 Python
深入理解python协程
Jun 15 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连接SQLServer2005的实现方法(附ntwdblib.dll下载)
2012/07/02 PHP
php shell超强免杀、减少体积工具实现代码
2012/10/16 PHP
destoon实现资讯信息前面调用它所属分类的方法
2014/07/15 PHP
必须收藏的23个php实用代码片段
2016/02/02 PHP
php+js实现裁剪任意形状图片
2018/10/31 PHP
Laravel解决nesting level错误和隐藏index.php的问题
2019/10/12 PHP
图片上传插件jquery.uploadify详解
2013/11/15 Javascript
javascript简单性能问题及学习笔记
2014/02/04 Javascript
JavaScript字符串对象slice方法入门实例(用于字符串截取)
2014/10/16 Javascript
jquery提示效果实例分析
2014/11/25 Javascript
DOM节点深度克隆函数cloneNode()用法实例
2015/01/12 Javascript
javascript实现的固定位置悬浮窗口实例
2015/04/30 Javascript
jQuery弹出层插件popShow用法示例
2017/01/23 Javascript
浅谈vue引入css,less遇到的坑和解决方法
2018/01/20 Javascript
vue中实现methods一个方法调用另外一个方法
2018/02/08 Javascript
Angularjs之如何在跨域请求中传输Cookie的方法
2018/06/01 Javascript
webpack4.0 入门实践教程
2018/10/08 Javascript
jquery实现动态改变css样式的方法分析
2019/05/27 jQuery
详解 javascript对象创建模式
2020/10/30 Javascript
python中实现php的var_dump函数功能
2015/01/21 Python
python 获取微信好友列表的方法(微信web)
2019/02/21 Python
python中关于数据类型的学习笔记
2020/07/19 Python
html5开发之viewport使用
2013/10/17 HTML / CSS
VICHY薇姿英国官网:全球专业敏感肌护肤领先品牌
2017/07/04 全球购物
南京迈特望C/C++面试题
2012/07/09 面试题
博士学位自我鉴定范文
2013/12/26 职场文书
员工工作表扬信范文
2014/01/13 职场文书
日本语毕业生自荐信
2014/02/01 职场文书
单位委托书范本
2014/04/04 职场文书
大学生励志演讲稿
2014/04/25 职场文书
干部四风问题整改措施思想汇报
2014/10/13 职场文书
2015年元旦促销方案书
2014/12/09 职场文书
英语感谢信范文
2015/01/20 职场文书
会议欢迎词范文
2015/01/27 职场文书
初中班干部工作总结
2015/08/10 职场文书
springboot 自定义配置 解决Boolean属性不生效
2022/03/18 Java/Android