Trying to use Selenium with Chrome in a python script.
I get the following error:
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
I know the location of the chromedriver executable. How do I add it to the PATH?
thank you
Go to the terminal and type the command: sudo nano /etc/paths. Enter the password. At the bottom of the file, add the path of your ChromeDriver. Type Y to save.
Finally, all you need to do is create a new ChromeDriver instance: WebDriver driver = new ChromeDriver(); driver. get("http://www.google.com"); Therefore, download the version of chromedriver you need, unzip it somewhere on your PATH (or specify the path to it via a system property), then run the driver.
You can specify the absolute path to your chrome driver in your script as such:
from selenium import webdriver driver = webdriver.Chrome(executable_path='/path/to/driver/chromedriver')
Or you can add the path to your webdriver in the PATH
system variable as so:
export PATH=$PATH:/path/to/driver/chrome-driver
You may add the above line to your /home/<user>/.profile
file to make it permanent.
Tested on Ubuntu 17.10 running Python 2.7.14
Hope this helps!
The solution posted by @AnythingIsFine is indeed correct.
However in my case my pytest was still unable to find the chromedriver (despite it was correctly added to the PATH and from the terminal I could execute it).
So I've solved by adding an alias of the chromedriver
in the /usr/bin
directory:
sudo ln -s /path/to/chromedriver /usr/bin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With