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 相关文章推荐
简单介绍利用TK在Python下进行GUI编程的教程
Apr 13 Python
Python处理JSON时的值报错及编码报错的两则解决实录
Jun 26 Python
python 开发的三种运行模式详细介绍
Jan 18 Python
python实现决策树
Dec 21 Python
Python+PIL实现支付宝AR红包
Feb 09 Python
python实现俄罗斯方块游戏
Mar 25 Python
详解Django中间件执行顺序
Jul 16 Python
Python + selenium + requests实现12306全自动抢票及验证码破解加自动点击功能
Nov 23 Python
tensorflow入门:TFRecordDataset变长数据的batch读取详解
Jan 20 Python
Python super()函数使用及多重继承
May 06 Python
Python中如何引入第三方模块
May 27 Python
Python matplotlib 利用随机函数生成变化图形
Apr 26 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
基于curl数据采集之单页面并行采集函数get_htmls的使用
2013/04/28 PHP
php实现查看邮件是否已被阅读的方法
2013/12/03 PHP
windows服务器中检测PHP SSL是否开启以及开启SSL的方法
2014/04/25 PHP
使用PHPExcel操作Excel用法实例分析
2015/03/26 PHP
深入理解PHP之OpCode原理详解
2016/06/01 PHP
PHP实现上传图片到 zimg 服务器
2016/10/19 PHP
javascript js cookie的存储,获取和删除
2007/12/29 Javascript
jQuery UI Dialog 创建友好的弹出对话框实现代码
2012/04/12 Javascript
jquery多选项卡效果实例代码(附效果图)
2013/03/23 Javascript
js计算字符串长度包含的中文是utf8格式
2013/10/15 Javascript
手机号码,密码正则验证
2014/09/04 Javascript
jQuery+HTML5实现图片上传前预览效果
2015/08/20 Javascript
jquery+css实现绚丽的横向二级下拉菜单-附源码下载
2015/08/23 Javascript
jquery validate demo 基础
2015/10/29 Javascript
JavaScript数据绑定实现一个简单的 MVVM 库
2016/04/08 Javascript
node实现简单的增删改查接口实例代码
2019/08/22 Javascript
JS实现轮播图效果
2020/01/11 Javascript
Vue 技巧之控制父类的 slot
2020/02/24 Javascript
Vue filter 过滤器、以及在table中的使用介绍
2020/09/07 Javascript
vue仿携程轮播图效果(滑动轮播,下方高度自适应)
2021/02/11 Vue.js
使用Python编写提取日志中的中文的脚本的方法
2015/04/30 Python
Python判断列表是否已排序的各种方法及其性能分析
2016/06/20 Python
Python列表list解析操作示例【整数操作、字符操作、矩阵操作】
2017/07/25 Python
浅谈python日志的配置文件路径问题
2018/04/28 Python
tensorflow 获取模型所有参数总和数量的方法
2018/06/14 Python
python虚拟环境迁移方法
2019/01/03 Python
Python values()与itervalues()的用法详解
2019/11/27 Python
python 的numpy库中的mean()函数用法介绍
2020/03/03 Python
突袭HTML5之Javascript API扩展3—本地存储全新体验
2013/01/31 HTML / CSS
彪马俄罗斯官网:PUMA俄罗斯
2019/07/13 全球购物
护理学专业推荐信
2013/12/03 职场文书
高中军训感言600字
2014/03/11 职场文书
信访工作个人总结
2015/03/03 职场文书
外贸英文求职信范文
2015/03/19 职场文书
幼儿园教师安全责任书
2015/05/08 职场文书
骆驼祥子读书笔记
2015/06/26 职场文书