pythonselenium-webdriverwebautomation

Error : "cannot connect to chrome at 127.0.0.1:54613 from session not created: This version of ChromeDriver only supports Chrome version 114


Consider:

import undetected_chromedriver as uc
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import time


# Set up Chrome WebDriver
service = Service()
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--profile-directory=Default")
options.add_argument("--user-data-dir=C:\\Users\\athar\\AppData\\Local\\Google\\Chrome\\User Data\\")

driver = uc.Chrome(service = service, options = options)

driver.get("https://gmail.com/")
time.sleep(10)

# Close the browser
driver.quit()

I just wanted to open Gmail in a Chrome profile, so that I won’t need to login every time and can activate extensions using keyboard shortcuts. Running the above script is giving a chromedriver version error. How can I use the correct version of chromedriver? What do I need to download and what driver path do I need to pass to the web driver function?

Complete Error:

Traceback (most recent call last):
  File "d:\programming\Python\Freelance\ExtensionAutomation\test.py", line 16, in <module>
    driver = uc.Chrome(service = service, options = options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 466, in __init__
    super(Chrome, self).__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 56, in __init__
    super().__init__(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 724, in start_session
    super(selenium.webdriver.chrome.webdriver.WebDriver, self).start_session(
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 290, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute
    self.error_handler.check_response(response)
  File "C:\Users\athar\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to chrome at 127.0.0.1:54613
from session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 116.0.5845.110
Stacktrace:
Backtrace:
        GetHandleVerifier [0x00FDA813+48355]
        (No symbol) [0x00F6C4B1]
        (No symbol) [0x00E75358]
        (No symbol) [0x00E961AC]
        (No symbol) [0x00E906B4]
        (No symbol) [0x00E90491]
        (No symbol) [0x00EC0C55]
        (No symbol) [0x00EC093C]
        (No symbol) [0x00EBA536]
        (No symbol) [0x00E982DC]
        (No symbol) [0x00E993DD]
        GetHandleVerifier [0x0123AABD+2539405]
        GetHandleVerifier [0x0127A78F+2800735]
        GetHandleVerifier [0x0127456C+2775612]
        GetHandleVerifier [0x010651E0+616112]
        (No symbol) [0x00F75F8C]
        (No symbol) [0x00F72328]
        (No symbol) [0x00F7240B]
        (No symbol) [0x00F64FF7]
        BaseThreadInitThunk [0x768D7D59+25]
        RtlInitializeExceptionChain [0x77C6B79B+107]
        RtlClearBits [0x77C6B71F+191]

Solution

  • Your Chrome browser updated to a new version that is not currently supported by this method. You could try download the driver by hand in this web (you should get the chrome-driver according to your PC and your Chrome version (117 in this case)):

    https://googlechromelabs.github.io/chrome-for-testing/#stable

    Then you only need to change the Service statement to aim that webdriver as follows:

    service=Service(executable_path=r"path_to_driver\chromedriver.exe")