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中的引用和拷贝浅析
Nov 22 Python
用map函数来完成Python并行任务的简单示例
Apr 02 Python
儿童编程python入门
May 08 Python
解决tensorflow模型参数保存和加载的问题
Jul 26 Python
python hbase读取数据发送kafka的方法
Dec 27 Python
python实现文件批量编码转换及注意事项
Oct 14 Python
Python 内置变量和函数的查看及说明介绍
Dec 25 Python
python两个_多个字典合并相加的实例代码
Dec 26 Python
Python 实现自动获取种子磁力链接方式
Jan 16 Python
python3.6连接mysql数据库及增删改查操作详解
Feb 10 Python
pandas分组聚合详解
Apr 10 Python
Django展示可视化图表的多种方式
Apr 08 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提取数据库内容中的图片地址并循环输出
2010/03/21 PHP
php通过隐藏表单控件获取到前两个页面的url
2014/09/09 PHP
PHP 在数组中搜索给定的简单实例 array_search 函数
2016/06/13 PHP
thinkPHP分组后模板无法加载问题解决方法
2016/07/12 PHP
phpstudy2018升级MySQL5.5为5.7教程(图文)
2018/10/24 PHP
JScript中的&quot;this&quot;关键字使用方式补充材料
2007/03/08 Javascript
利用Dojo和JSON建立无限级AJAX动态加载的功能模块树
2007/03/24 Javascript
JQuery拖拽元素改变大小尺寸实现代码
2012/12/10 Javascript
JavaScript关闭当前页面(窗口)不带任何提示
2014/03/26 Javascript
nodejs简单实现中英文翻译
2015/05/04 NodeJs
jquery.mousewheel实现整屏翻屏效果
2015/08/30 Javascript
JavaScript引用类型和基本类型详解
2016/01/06 Javascript
js获取Html元素的实际宽度高度的方法
2016/05/19 Javascript
jQuery删除当前节点元素
2016/12/07 Javascript
详解使用angularjs的ng-options时如何设置默认值(初始值)
2017/07/18 Javascript
详解在create-react-app使用less与antd按需加载
2018/12/06 Javascript
微信小程序的mpvue框架快速上手指南
2019/05/15 Javascript
小程序开发之模态框组件封装
2020/04/23 Javascript
python之DataFrame实现excel合并单元格
2021/02/22 Python
python 处理dataframe中的时间字段方法
2018/04/10 Python
Pandas中DataFrame的分组/分割/合并的实现
2019/07/16 Python
python使用if语句实现一个猜拳游戏详解
2019/08/27 Python
Python 批量刷博客园访问量脚本过程解析
2019/08/30 Python
python实现井字棋小游戏
2020/03/04 Python
Python sorted排序方法如何实现
2020/03/31 Python
在pycharm中关掉ipython console/PyDev操作
2020/06/09 Python
美国批发供应商:Kole Imports
2019/04/10 全球购物
What's the difference between an interface and abstract class? (接口与抽象类有什么区别)
2012/10/29 面试题
篮球兴趣小组活动总结
2014/07/07 职场文书
党的群众路线教育实践活动对照检查材料思想汇报(党员篇)
2014/09/25 职场文书
2014年大学生社会实践自我鉴定
2014/09/26 职场文书
小学秋季运动会报道稿
2014/09/30 职场文书
2014年少先队工作总结
2014/12/03 职场文书
2014矛盾纠纷排查调处工作总结
2014/12/09 职场文书
幼儿园小班教学反思
2016/03/03 职场文书
python 通过使用Yolact训练数据集
2021/04/06 Python