Python3+selenium配置常见报错解决方案

 更新时间:2020年08月28日 10:39:12   作者:罗维翩  
这篇文章主要介绍了Python3+selenium配置常见报错解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

第一个坑:'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的安装目录下

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 入门tensorflow教程之TensorBoard可视化模型训练

    入门tensorflow教程之TensorBoard可视化模型训练

    在本篇文章中,主要介绍 了TensorBoard 的基础知识,并了解如何可视化训练模型中的一些基本信息,希望对大家的TensorBoard可视化模型训练有所帮助
    2021-08-08
  • Linux上Miniconda的安装的实现步骤

    Linux上Miniconda的安装的实现步骤

    Miniconda是一个轻量级、免费且开源的跨平台软件包管理系统,本文主要介绍了Linux上Miniconda的安装的实现步骤,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03
  • 基于Python实现定时自动给微信好友发送天气预报

    基于Python实现定时自动给微信好友发送天气预报

    这篇文章主要介绍了基于Python实现定时自动给微信好友发送天气预报的实现代码,,需要的朋友可以参考下
    2018-10-10
  • Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)

    Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)

    这篇文章主要介绍了Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • python操作xml文件详细介绍

    python操作xml文件详细介绍

    这篇文章主要介绍了python操作xml文件详细介绍,着重介绍了获取XML标签的属性和值的方法,需要的朋友可以参考下
    2014-06-06
  • Django URL和View的关系说明

    Django URL和View的关系说明

    这篇文章主要介绍了Django URL和View的关系说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-03-03
  • 关于Python中的 oct 函数与 min 函数

    关于Python中的 oct 函数与 min 函数

    本文主要介绍了Python oct 函数与 min 函数;oct 函数是 Python 内置函数,主要将一个整数转为八进制,与 ord 函数 / chr 函数 有点类似;min 函数返回给定参数的最小值,参数可以为序列语法,感兴趣的小伙伴请继续阅读下文
    2021-09-09
  • python中@符号实例详解

    python中@符号实例详解

    @是一个装饰器,针对函数,起调用传参的作用,下面这篇文章主要给大家介绍了关于python中@符号的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
    2022-12-12
  • 使用python和opencv的mask实现抠图叠加

    使用python和opencv的mask实现抠图叠加

    这篇文章主要介绍了使用python和opencv的mask实现抠图叠加操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-04-04
  • 详解如何使用Pandas删除DataFrame中的非数字类型数据

    详解如何使用Pandas删除DataFrame中的非数字类型数据

    在数据处理和分析过程中,经常会遇到需要清洗数据的情况,本文将详细介绍如何使用Pandas删除DataFrame中的非数字类型数据,感兴趣的小伙伴可以了解下
    2024-03-03

最新评论