selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager error using Selenium and ChromeDriver
Asked Answered
K

5

5

I can't figure out why my code it's always getting an error

This is my code:

from selenium import webdriver

url = "https://google.com/"
path = "C:/Users/thefo/OneDrive/Desktop/summer 2023/chromedriver_win32"

driver = webdriver.Chrome(path)
driver.get(url)

Path of chromedriver:

path from chromedriver

and this is the error that always appears:

Traceback (most recent call last):
  File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 42, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 74, 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\thefo\OneDrive\Desktop\summer 2023\Projeto Bot Discord - BUFF SELL CHECKER\teste2.py", line 6, in <module>
    driver = webdriver.Chrome(path)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 47, in __init__
    self.service.path = DriverFinder.get_path(self.service, self.options)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 44, in get_path
    raise NoSuchDriverException(f"Unable to obtain {service.path} using Selenium Manager; {err}")
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain chromedriver using Selenium Manager; 'str' object has no attribute 'capabilities'; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
Kingsly answered 14/7, 2023 at 22:19 Comment(1)
use this link https://stackoverflow.com/a/77815918/12780274Oralee
G
8

This error message...

Traceback (most recent call last):
  File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 42, in get_path
    path = SeleniumManager().driver_location(options) if path is None else path
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...implies that the version of Selenium which you are using is v4.6 or above.


Selenium Manager

In such cases Selenium Manager can silently download the matching ChromeDriver and you don't have to explicitly mention the chromedriver path anymore.


Solution

Your minimal code block can be:

from selenium import webdriver

url = "https://google.com/"
driver = webdriver.Chrome()
driver.get(url)
Grigg answered 14/7, 2023 at 22:28 Comment(0)
C
1

You should remove the path from webdriver.Chrome() to solve the error as shown below. *This is recommended and you can see the answers of my question about which version of chrome driver webdriver.Chrome() gets:

from selenium import webdriver

url = "https://google.com/"
# path = "C:/Users/thefo/OneDrive/Desktop/summer 2023/chromedriver_win32"

driver = webdriver.Chrome() # Here
driver.get(url)

Or, you should set the path to Service() and set it to webdriver.Chrome() to solve the error as shown below:

from selenium.webdriver.chrome.service import Service
from selenium import webdriver

url = "https://google.com/"
path = "C:/Users/thefo/OneDrive/Desktop/summer 2023/chromedriver_win32"

service = Service(executable_path=path) # Here
driver = webdriver.Chrome(service=service) # Here
driver.get(url)
Cofield answered 16/8, 2023 at 15:25 Comment(0)
E
0

ref : https://pypi.org/project/webdriver-manager/#use-with-chrome

Install manager:

pip install webdriver-manager

Use with Chrome for selenium 4

   from selenium import webdriver
   from selenium.webdriver.chrome.service import Service as ChromeService
   from webdriver_manager.chrome import ChromeDriverManager

   driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
Electrolyte answered 22/9, 2023 at 8:2 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Psychasthenia
V
0

If it was installed via conda on Windows with selenium >= 4.6:

from selenium import webdriver
import os
os.environ['SE_MANAGER_PATH'] = os.environ['CONDA_PREFIX'] + '/Scripts/selenium-manager.exe'
driver = webdriver.Chrome()
Vaclava answered 18/8, 2024 at 23:55 Comment(0)
I
0

I also had the same problem, which was solved by running the file in an interactive window instead of running the code directly. I am using VS code; that option is in the drop-down menu of the run button.

Also, Selenium has been updated for Chrome and now the code has been simplified, you don't need to describe the path anymore, selenium does that automatically. This is the code I used;

from selenium import webdriver

browser = webdriver.Chrome()

browser.get('https://www.google.co.uk/')

I will also leave the link to the GitHub page with all the codes;

https://github.com/SergeyPirogov/webdriver_manager#use-with-chrome

Intarsia answered 4/10, 2024 at 2:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.