当前位置: 首页 > 知识库问答 >
问题:

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

赵驰
2023-03-14

我正在尝试使用Python 3.7 Selenium GeckoDrive 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。

系统:Windows 7 x64 Firefox 65.0 64位,最新硒,geckodriv0.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)的更新版本中,我应该在连接期间指定一些选项?

共有1个答案

子车高超
2023-03-14

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

>

  • 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/.
    

    火狐: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
    

  •  类似资料: