chromedriver executable is in PATH but still getting error

1.6k Views Asked by At

I'm trying to use selenium but I'm getting the error

'chromedriver' executable needs to be in PATH.

But I know for a fact that it's in PATH. I have the exe located in C:\WebDriver\bin. It's been added to my system variables System variables image. Running chromedriver in the command prompt successfully returns

Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

I've restarted my computer. I tried directly specifying the executable_path

driver = Chrome(executable_path=r"C:\WebDriver\bin\chromedriver.exe")

I used ProcessMonitor if anyone can make sense of these logs (filter: "path contains chromedriver")

Update:

Using webdriver-manager

from selenium import webdriver    
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

Gave me the error

ValueError: Could not get version for Chrome with this command: google-chrome --version || google-chrome-stable --version
2

There are 2 best solutions below

0
On

Try this :

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\WebDriver\bin\chromedriver.exe')
5
On

Try to use webdriver-manager package:

pip install webdriver-manager

the code should look like this:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

The module download driver automatically and store it at known path for selenium. It will solve all of kinda troubles with driver path