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实现一个简单的能够发送带附件的邮件程序的教程
Apr 08 Python
Python遍历目录中的所有文件的方法
Jul 08 Python
Python实现在线暴力破解邮箱账号密码功能示例【测试可用】
Sep 06 Python
pandas每次多Sheet写入文件的方法
Dec 10 Python
python中实现控制小数点位数的方法
Jan 24 Python
用python中的matplotlib绘制方程图像代码
Nov 21 Python
利用Python的turtle库绘制玫瑰教程
Nov 23 Python
Python猴子补丁知识点总结
Jan 05 Python
如何卸载python插件
Jul 08 Python
详解Anaconda安装tensorflow报错问题解决方法
Nov 01 Python
Python urllib3软件包的使用说明
Nov 18 Python
python脚本框架webpy模板控制结构
Nov 20 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安全配置
2006/12/06 PHP
PHP面向对象概念
2011/11/06 PHP
PHP中去除换行解决办法小结(PHP_EOL)
2011/11/27 PHP
php获取CSS文件中图片地址并下载到本地的方法
2014/12/02 PHP
解决PHP里大量数据循环时内存耗尽的方法
2015/10/10 PHP
JavaScript 保存数组到Cookie的代码
2010/04/14 Javascript
JavaScript传递变量: 值传递?引用传递?
2011/02/22 Javascript
Javascript公共脚本库系列(一): 弹出层脚本
2011/02/24 Javascript
关于extjs treepanel复选框选中父节点与子节点的问题
2013/04/02 Javascript
JavaScript的继承的封装介绍
2013/10/15 Javascript
深入浅析JavaScript系列(13):This? Yes,this!
2016/01/05 Javascript
JavaScript实现图片本地预览功能【不用上传至服务器】
2017/09/20 Javascript
基于百度地图api清除指定覆盖物(Overlay)的方法
2018/01/26 Javascript
vue 全选与反选的实现方法(无Bug 新手看过来)
2018/02/09 Javascript
js中对象与对象创建方法的各种方法
2019/02/27 Javascript
从零学Python之hello world
2014/05/21 Python
python实现用于测试网站访问速率的方法
2015/05/26 Python
详谈套接字中SO_REUSEPORT和SO_REUSEADDR的区别
2018/04/28 Python
Python 闭包,函数分隔作用域,nonlocal声明非局部变量操作示例
2019/10/14 Python
python3连接mysql获取ansible动态inventory脚本
2020/01/19 Python
python读取hdfs并返回dataframe教程
2020/06/05 Python
Python3如何实现Win10桌面自动切换
2020/08/11 Python
CSS3 三维变形实现立体方块特效源码
2016/12/15 HTML / CSS
CSS Houdini实现动态波浪纹效果
2019/07/30 HTML / CSS
阻止移动设备(手机、pad)浏览器双击放大网页的方法
2014/06/03 HTML / CSS
StubHub德国:购买和出售门票
2017/09/06 全球购物
Perfumetrader荷兰:香水、化妆品和护肤品在线商店
2017/09/15 全球购物
西班牙著名的珠宝首饰品牌:P D PAOLA
2018/09/15 全球购物
中专生毕业自我鉴定
2013/11/01 职场文书
关于逃课的检讨书
2014/01/23 职场文书
火锅店创业计划书范文
2014/02/02 职场文书
大学迎新晚会主持词
2014/03/24 职场文书
2014年新生军训方案
2014/05/01 职场文书
英语自我介绍演讲稿
2014/09/01 职场文书
党性分析材料格式
2014/12/19 职场文书
JS精髓原型链继承及构造函数继承问题纠正
2022/06/16 Javascript