WebDriverException:消息:通过Python 3.7使用GeckoDriver Firefoxv65和Selenium的newSession

发布于 2021-01-29 17:32:21

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

WebDriverException: Message: newSession

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

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

系统 :Windowns 7 x64 + Firefox 65.0 64位,最新的硒,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

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

关注者
0
被浏览
51
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

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

    • 的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

      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:

    • 壁虎驱动程序: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

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

      Mozilla Firefox 65.0

    我已经采用了自己的代码并执行了添加 参数 的代码, executable_path 如下所示:

    • 代码块:

      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()

    • 控制台输出:

      Page Title is : Google
      

    作为一条经验法则,始终遵循[ GeckoDriver](https://firefox-source-

    docs.mozilla.org/testing/geckodriver/geckodriver/Support.html)

    Selenium

    Firefox
    Browser

    兼容性表中
    的配置矩阵
    __



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看