WebDriverException:消息:通过Python 3.7使用GeckoDriver Firefox v65和Selenium的newSession [英] WebDriverException: Message: newSession with GeckoDriver Firefox v65 and Selenium through Python 3.7

查看:80
本文介绍了WebDriverException:消息:通过Python 3.7使用GeckoDriver Firefox v65和Selenium的newSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python 3.7 + Selenium + Geckodriver + Firefox v65.0进行剪贴. 新窗口打开,但是Firefox没有向Python发送有关会话的正确响应,并在30秒后崩溃并显示错误:

I am trying to use Python 3.7 + Selenium + Geckodriver + Firefox v65.0 for scrapping. New window is opening, but Firefox does not sent correct respond about session to Python and crashes after 30 seconds with an error:

WebDriverException: Message: newSession

如果我将Firefox降级为60.0.2版-则所有版本的Geckodriver v0.22、0.23和0.24均可正常使用.

In case if I downgrade Firefox to version 60.0.2 - all works correctly with all versions Geckodriver v0.22, 0.23 and 0.24.

即使我尝试使用从0.22到0.24的其他geckodrivers,Firefox 63.0、65.0和66beta版本也不起作用.

Firefox version 63.0, 65.0 and 66beta does not work, even if I try different geckodrivers from 0.22 to 0.24.

系统:Windowns 7 x64 + Firefox 65.0 64位,最新的硒,geckodriver v0.24.0.

System: Windowns 7 x64+ Firefox 65.0 64bit, newest selenium, geckodriver v0.24.0.

我的代码:

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException

with webdriver.Firefox() as driver:
    driver.get("http://google.com")

错误说明:

WebDriverException                        Traceback (most recent call last)
<ipython-input-10-5240f957d3b7> in <module>
----> 1 with webdriver.Firefox() as driver:
      2     driver.get("http://google.com")

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, options, service_log_path, firefox_options, service_args, desired_capabilities, log_path, keep_alive)
    172                 command_executor=executor,
    173                 desired_capabilities=capabilities,
--> 174                 keep_alive=True)
    175 
    176         # Selenium remote

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    155             warnings.warn("Please use FirefoxOptions to set browser profile",
    156                           DeprecationWarning, stacklevel=2)
--> 157         self.start_session(capabilities, browser_profile)
    158         self._switch_to = SwitchTo(self)
    159         self._mobile = Mobile(self)

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in start_session(self, capabilities, browser_profile)
    250         parameters = {"capabilities": w3c_caps,
    251                       "desiredCapabilities": capabilities}
--> 252         response = self.execute(Command.NEW_SESSION, parameters)
    253         if 'sessionId' not in response:
    254             response = response['value']

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: newSession

问题: 如何使Firefox 65与Selenium兼容? 也许在较新版本的Firefox(61.0+)中,我应该在连接期间指定一些选项吗?

Queston: How it is possible to make Firefox 65 work with Selenium? Maybe in newer versions of Firefox (61.0+) I should specify some options during connection?

推荐答案

不确定哪里出了问题,但似乎有多个二进制版本的混淆.但是我正在使用以下配置:

Not sure where things are going wrong but there seems to be a mixup with multiple binary versions. However I am using the following configuration:

  • Python:3.6.1

  • Python: 3.6.1

C:\Users\user_name>python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

  • 硒:3.141.0

  • Selenium: 3.141.0

    C:\Users\user_name>pip show -V selenium
    Name: selenium
    Version: 3.141.0
    Summary: Python bindings for Selenium
    Home-page: https://github.com/SeleniumHQ/selenium/
    Author: UNKNOWN
    Author-email: UNKNOWN
    License: Apache 2.0
    Location: c:\python\lib\site-packages
    Requires: urllib3
    Required-by:
    

  • GeckoDriver:0.24.0

  • GeckoDriver: 0.24.0

    C:\Utility\BrowserDrivers>geckodriver.exe -V
    geckodriver 0.24.0 ( 2019-01-28)
    
    The source code of this program is available from
    testing/geckodriver in https://hg.mozilla.org/mozilla-central.
    
    This program is subject to the terms of the Mozilla Public License 2.0.
    You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
    

  • Firefox:Mozilla Firefox 65.0

  • Firefox: Mozilla Firefox 65.0

    C:\Program Files\Mozilla Firefox>firefox -v |more
    Mozilla Firefox 65.0
    

  • 我已经采用了自己的代码,并添加了自变量 executable_path 来执行它,如下所示:

    I have taken your own code and executed it adding the argument executable_path as follows:

    • 代码块:

    • Code Block:

    from selenium import webdriver
    
    with webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe') as driver:
        driver.get("http://google.com")
        print("Page Title is : %s" %driver.title)
        driver.quit()
    

  • 控制台输出:

  • Console Output:

    Page Title is : Google
    

  • 这篇关于WebDriverException:消息:通过Python 3.7使用GeckoDriver Firefox v65和Selenium的newSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆