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编程之属性和方法实例详解
May 19 Python
深入学习Python中的装饰器使用
Jun 20 Python
python selenium 获取标签的属性值、内容、状态方法
Jun 22 Python
python获取指定字符串中重复模式最高的字符串方法
Jun 29 Python
实践Vim配置python开发环境
Jul 02 Python
python实现n个数中选出m个数的方法
Nov 13 Python
Python实现连接MySql数据库及增删改查操作详解
Apr 16 Python
python全栈知识点总结
Jul 01 Python
解决Python3 控制台输出InsecureRequestWarning问题
Jul 15 Python
在python image 中安装中文字体的实现方法
Aug 22 Python
Python实现分数序列求和
Feb 25 Python
Python轻量级web框架bottle使用方法解析
Jun 13 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
1982年日本摄影师镜头下的中国孩子 那无忧无虑的童年
2020/03/12 杂记
关于mysql字符集设置了character_set_client=binary 在gbk情况下会出现表描述是乱码的情况
2013/01/06 PHP
PHP实现采集抓取淘宝网单个商品信息
2015/01/08 PHP
浅谈PHP中其他类型转化为Bool类型
2016/03/28 PHP
PHP获取访问页面HTTP状态码的实现代码
2016/11/03 PHP
基于laravel-admin 后台 列表标签背景的使用方法
2019/10/03 PHP
jquery last-child 列表最后一项的样式
2010/01/22 Javascript
jquery无刷新验证邮箱地址实现实例
2014/02/19 Javascript
JQuery为页面Dom元素绑定事件及解除绑定方法
2014/04/23 Javascript
For循环中分号隔开的3部分的执行顺序探讨
2014/05/27 Javascript
javascript简单实现类似QQ头像弹出效果的方法
2015/08/03 Javascript
js和jquery分别验证单选框、复选框、下拉框
2015/12/17 Javascript
jquery仿QQ登录账号选择下拉框效果
2016/03/22 Javascript
只要1K 纯JS脚本送你一朵3D红色玫瑰
2016/08/09 Javascript
探究JavaScript中的五种事件处理程序方式
2016/12/07 Javascript
从零开始学习Node.js系列教程五:服务器监听方法示例
2017/04/13 Javascript
以v-model与promise两种方式实现vue弹窗组件
2018/05/21 Javascript
JavaScript 高性能数组去重的方法
2018/09/20 Javascript
如何为你的JavaScript代码日志着色详解
2019/04/08 Javascript
[00:23]魔方之谜解锁款式
2018/12/20 DOTA
jupyter notebook读取/导出文件/图片实例
2020/04/16 Python
python语言是免费还是收费的?
2020/06/15 Python
python获取百度热榜链接的实例方法
2020/08/25 Python
CSS3 函数技巧 用css 实现js实现的事情(clac Counters Tooltip)
2017/08/15 HTML / CSS
AmazeUI 缩略图的实现示例
2020/08/18 HTML / CSS
写一个用矩形法求定积分的通用函数
2012/11/08 面试题
业务主管岗位职责
2013/11/20 职场文书
工厂仓管员岗位职责
2014/01/01 职场文书
幼儿园教师考核制度
2014/02/01 职场文书
《雾凇》教学反思
2014/02/17 职场文书
《守株待兔》教学反思
2014/03/01 职场文书
2014学雷锋活动总结
2014/03/09 职场文书
节水倡议书范文
2014/04/15 职场文书
小学教师师德整改措施
2014/09/29 职场文书
网络管理员岗位职责
2015/02/12 职场文书
选调生挂职锻炼工作总结
2015/10/23 职场文书