1

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
tape74
  • 75
  • 1
  • 9
  • Does this answer your question? [chromedriver.exe is ALREADY in PATH but still getting error message](https://stackoverflow.com/questions/58752089/chromedriver-exe-is-already-in-path-but-still-getting-error-message) – Axisnix Mar 17 '21 at 20:07
  • unfortunately no @FluxedScript – tape74 Mar 17 '21 at 21:03

2 Answers2

0

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

Vova
  • 3,117
  • 2
  • 15
  • 23
  • Using this I got the error: ValueError: Could not get version for Chrome with this command: google-chrome --version || google-chrome-stable --version @Vova – tape74 Mar 17 '21 at 21:15
  • @tape74 interesting, seems like there's a bug on it. – Vova Mar 17 '21 at 21:27
  • @tape74 does it work well with firefox? `from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())` – Vova Mar 17 '21 at 21:38
  • Now the error: `SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line` my exe is in C:\Program Files\Mozilla Firefox tho – tape74 Mar 19 '21 at 08:46
  • Solution suggested here https://stackoverflow.com/questions/65318382/expected-browser-binary-location-but-unable-to-find-binary-in-default-location but I'm not sure how to use the options thing with webdriver-manager – tape74 Mar 19 '21 at 08:47
0

Try this :

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\WebDriver\bin\chromedriver.exe')
Elyes Lounissi
  • 405
  • 3
  • 12