Forums

Selenium Chromedriver help needed

Hi all, any help please! Trying to use Selenium through Python but can't even get started! I have put latest chromedriver is my local directory as python script, here is my code:

**from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')**

but I keep getting the following error, wasted days trying to sort it but nothing works. Any help greatly appreciated :)

**Traceback (most recent call last):
  File "C:\Users\philc\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\philc\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 87, 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\philc\anaconda3\envs\PythonTradingview\Selenium Example.py", line 4, in <module>
    driver = webdriver.Chrome('./chromedriver')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\philc\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\philc\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 49, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\philc\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."
                                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'capabilities'
Process finished with exit code 1**

[edit by admin: formatting]

You'll want to use the chromedriver that's already included as it matches the version of the chrome browser that's installed. Check out this help page to get started - https://help.pythonanywhere.com/pages/selenium/