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创建日历实例
Aug 21 Python
python snownlp情感分析简易demo(分享)
Jun 04 Python
python 接口_从协议到抽象基类详解
Aug 24 Python
Python OpenCV获取视频的方法
Feb 28 Python
Python使用pymysql从MySQL数据库中读出数据的方法
Jul 25 Python
Python3随机漫步生成数据并绘制
Aug 27 Python
python 随机打乱 图片和对应的标签方法
Dec 14 Python
详解python3 + Scrapy爬虫学习之创建项目
Apr 12 Python
Tensorflow 卷积的梯度反向传播过程
Feb 10 Python
Pyecharts 动态地图 geo()和map()的安装与用法详解
Mar 25 Python
利用python 读写csv文件
Sep 10 Python
详解Python中Pyyaml模块的使用
Oct 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 文章中的远程图片采集到本地的代码
2009/07/30 PHP
php自动给文章加关键词链接的函数代码
2012/11/29 PHP
php生成过去100年下拉列表的方法
2015/07/20 PHP
利用PHP自动生成印有用户信息的名片
2016/08/01 PHP
微信利用PHP创建自定义菜单的方法
2016/08/01 PHP
轻松实现php文件上传功能
2017/02/17 PHP
jquery下jstree简单应用 - v1.0
2011/04/14 Javascript
javascript动态加载三
2012/08/22 Javascript
简约JS日历控件 实例代码
2013/07/12 Javascript
JavaScript作用域与作用域链深入解析
2013/12/06 Javascript
比例尺、缩略图、平移缩放之百度地图添加控件方法
2015/08/03 Javascript
浅谈JS函数定义方式的区别
2016/10/30 Javascript
js拖拽功能实现代码解析
2016/11/28 Javascript
如何使用vuejs实现更好的Form validation?
2017/04/07 Javascript
微信小程序promsie.all和promise顺序执行
2017/10/27 Javascript
详解关于Vue2.0路由开启keep-alive时需要注意的地方
2018/09/18 Javascript
vue地址栏直接输入路由无效问题的解决
2018/11/15 Javascript
es6基础学习之解构赋值
2018/12/10 Javascript
vue-cli3 从搭建到优化的详细步骤
2019/01/20 Javascript
浅谈nuxtjs校验登录中间件和混入(mixin)
2020/11/06 Javascript
Python 面向对象 成员的访问约束
2008/12/23 Python
Python实现发送QQ邮件的封装
2017/07/14 Python
Python Pandas找到缺失值的位置方法
2018/04/12 Python
python 2.7 检测一个网页是否能正常访问的方法
2018/12/26 Python
Django模型序列化返回自然主键值示例代码
2019/06/12 Python
python查找重复图片并删除(图片去重)
2019/07/16 Python
Python使用Matlab命令过程解析
2020/06/04 Python
Python爬虫使用bs4方法实现数据解析
2020/08/25 Python
详解使用python爬取抖音app视频(appium可以操控手机)
2021/01/26 Python
优质有机椰子产品:Dr. Goerg
2019/09/24 全球购物
岗位职责的含义
2013/11/17 职场文书
动物科学专业毕业生的自我评价
2013/11/29 职场文书
三个儿子教学反思
2014/02/03 职场文书
C++程序员求职信
2014/05/07 职场文书
水利水电建筑施工应届生求职信
2014/07/04 职场文书
致青春观后感
2015/06/09 职场文书