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中实现的RC4算法
Feb 14 Python
举例讲解Python中装饰器的用法
Apr 27 Python
Python实现从URL地址提取文件名的方法
May 15 Python
python 计算文件的md5值实例
Jan 13 Python
Python实现统计文本文件字数的方法
May 05 Python
Python实现加载及解析properties配置文件的方法
Mar 29 Python
python实现zabbix发送短信脚本
Sep 17 Python
django多个APP的urls设置方法(views重复问题解决)
Jul 19 Python
python多线程实现TCP服务端
Sep 03 Python
Python使用grequests(gevent+requests)并发发送请求过程解析
Sep 25 Python
python自动分箱,计算woe,iv的实例代码
Nov 22 Python
Django URL参数Template反向解析
Nov 24 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
利用js调用后台php进行数据处理原码
2006/10/09 PHP
php中文字母数字验证码实现代码
2008/04/25 PHP
php session 错误
2009/05/21 PHP
PHP中require和include路径问题详解
2014/12/25 PHP
php生成二维码
2015/08/10 PHP
微信 开发生成带参数的二维码的实例
2016/11/23 PHP
PHP实现防止表单重复提交功能【基于token验证】
2018/05/24 PHP
javascript之bind使用介绍
2011/10/09 Javascript
深入探讨JavaScript、JQuery屏蔽网页鼠标右键菜单及禁止选择复制
2014/06/10 Javascript
引用其它js时如何同时处理多个window.onload事件
2014/09/02 Javascript
JavaScript生成.xls文件的代码
2016/12/22 Javascript
echarts鼠标覆盖高亮显示节点及关系名称详解
2018/03/17 Javascript
vue 优化CDN加速的方法示例
2018/09/19 Javascript
原生JS实现旋转轮播图+文字内容切换效果【附源码】
2018/09/29 Javascript
vue.js实现的全选与全不选功能示例【基于elementui】
2018/12/03 Javascript
vue.js实现只能输入数字的输入框
2019/10/19 Javascript
[54:54]Newbee vs Serenity 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/18 DOTA
基于python3 类的属性、方法、封装、继承实例讲解
2017/09/19 Python
解读python logging模块的使用方法
2018/04/17 Python
Python字典深浅拷贝与循环方式方法详解
2020/02/09 Python
python使用docx模块读写docx文件的方法与docx模块常用方法详解
2020/02/17 Python
pandas按照列的值排序(某一列或者多列)
2020/12/13 Python
施华洛世奇韩国官网:SWAROVSKI韩国
2018/06/05 全球购物
New Balance德国官方网站:购买鞋子和服装
2019/08/31 全球购物
德国受欢迎的旅游和休闲网站:lastminute.de
2019/09/23 全球购物
Yahoo的PHP面试题
2014/05/26 面试题
.net C#面试题
2012/08/28 面试题
《忆江南》教学反思
2014/04/07 职场文书
音乐兴趣小组活动总结
2014/07/07 职场文书
公安交警中队队长个人对照检查材料思想汇报
2014/10/05 职场文书
三年级上册科学教学计划
2015/01/21 职场文书
律师催款函范文
2015/06/24 职场文书
2016公司新年问候语
2015/11/11 职场文书
Redis实现订单自动过期功能的示例代码
2021/05/08 Redis
Django REST framework 限流功能的使用
2021/06/24 Python
简单聊一聊SQL注入及防止SQL注入
2022/03/23 MySQL