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+pandas计算数据相关系数的实例
Jul 03 Python
django连接mysql配置方法总结(推荐)
Aug 18 Python
python 多线程中子线程和主线程相互通信方法
Nov 09 Python
python http基本验证方法
Dec 26 Python
详解python中TCP协议中的粘包问题
Mar 22 Python
详解python读取和输出到txt
Mar 29 Python
不归路系列:Python入门之旅-一定要注意缩进!!!(推荐)
Apr 16 Python
python scrapy爬虫代码及填坑
Aug 12 Python
python模式 工厂模式原理及实例详解
Feb 11 Python
PyCharm 专业版安装图文教程
Feb 20 Python
django使用JWT保存用户登录信息
Apr 22 Python
Python实现微信表情包炸群功能
Jan 28 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实现自动获取生成文章主题关键词功能的深入分析
2013/06/03 PHP
PHP base64编码后解码乱码的解决办法
2014/06/19 PHP
PHP_SELF,SCRIPT_NAME,REQUEST_URI区别
2014/12/24 PHP
PHP批量查询WordPress留言者E-mail地址实现方法
2015/02/15 PHP
PHP基本语法实例总结
2016/09/09 PHP
PHP之十六个魔术方法详细介绍
2016/11/01 PHP
微信 getAccessToken方法详解及实例
2016/11/23 PHP
PHP扩展Swoole实现实时异步任务队列示例
2019/04/13 PHP
Jquery css函数用法(判断标签是否拥有某属性)
2011/05/28 Javascript
js触发asp.net的Button的Onclick事件应用
2013/02/02 Javascript
document.createElement()用法
2013/03/13 Javascript
解析javascript系统错误:-1072896658的解决办法
2013/07/08 Javascript
详解Javascript动态操作CSS
2014/12/08 Javascript
jQuery的css()方法用法实例
2014/12/24 Javascript
分析了一下JQuery中的extend方法实现原理
2015/02/27 Javascript
浅谈js中的延迟执行和定时执行
2016/05/31 Javascript
AngularJS中$http服务常用的应用及参数
2016/08/22 Javascript
jQuery得到多个值只能用取Class ,不能用取ID的方法
2016/12/04 Javascript
jQuery实现6位数字密码输入框
2016/12/29 Javascript
d3.js实现立体柱图的方法详解
2017/04/28 Javascript
JS实现的文字间歇循环滚动效果完整示例
2018/02/13 Javascript
ES6 中可以提升幸福度的小功能
2018/08/06 Javascript
用js限制网页只在微信浏览器中打开(或者只能手机端访问)
2020/12/24 Javascript
ES6扩展运算符和rest运算符用法实例分析
2020/05/23 Javascript
Python实现连接两个无规则列表后删除重复元素并升序排序的方法
2018/02/05 Python
Python使用pylab库实现绘制直方图功能示例
2018/06/01 Python
Python中Numpy mat的使用详解
2019/05/24 Python
python3获取url文件大小示例代码
2019/09/18 Python
python 负数取模运算实例
2020/06/03 Python
Python3获取cookie常用三种方案
2020/10/05 Python
Django中如何用xlwt生成表格的方法步骤
2021/01/31 Python
惠普墨西哥官方商店:HP墨西哥
2016/12/01 全球购物
main 主函数执行完毕后,是否可能会再执行一段代码,给出说明
2012/12/05 面试题
外语系毕业生找工作的求职信
2013/11/28 职场文书
大学毕业生通用自我评价
2014/01/05 职场文书
开学典礼观后感
2015/06/15 职场文书