Search code examples
pythonpython-3.xselenium-webdriverselenium-chromedriver

Selenium not working with correct chromedriver version and chrome version


I want to just write a hello world with selenium and have the following code:

from selenium import webdriver
driver = webdriver.Chrome('C:/Users/[...]/chromedriver/chromedriver.exe')
driver.get("https://www.google.com")

But I keep getting the following error:

Traceback (most recent call last):
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 75, in driver_location
    browser = options.capabilities["browserName"]
              ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'capabilities'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\[...]\ets.py", line 3, in <module>
    driver = webdriver.Chrome('C:/Users/[...]/chromedriver/chromedriver.exe')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 51, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Username\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 40, in get_path
    msg = f"Unable to obtain driver for {options.capabilities['browserName']} using Selenium Manager."
                                         ^^^^^^^^^^^^^^^^^^^^

I am using Chrome version: 119.0.6045.200 And ChromeDriver: 119.0.6045.105

I cant find anything on it, thanks for the help


Solution

  • You can simply get the driver by:

    from selenium import webdriver
    
    driver = webdriver.Chrome()
    

    then:

    driver.get("https://www.google.com")
    

    You don't need driver.exe anymore

    doc: https://www.selenium.dev/blog/2022/introducing-selenium-manager/