WebDriverException: Message: newSession with GeckoDriver Firefox v65 and Selenium through Python 3.7

一曲冷凌霜 提交于 2019-12-17 14:55:21

问题


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

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.

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

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

My code:

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

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

Error description:

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: 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?


回答1:


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

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

    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
    

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
    

As a thumb rule always follow the configuration matrix from the GeckoDriver, Selenium and Firefox Browser compatibility chart



来源:https://stackoverflow.com/questions/54558321/webdriverexception-message-newsession-with-geckodriver-firefox-v65-and-seleniu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!