23

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

user7188934
  • 1,021
  • 3
  • 11
  • 17
  • 2
    Possible duplicate of [Error message: "'chromedriver' executable needs to be available in the path"](https://stackoverflow.com/questions/29858752/error-message-chromedriver-executable-needs-to-be-available-in-the-path) – JeffC Jan 11 '18 at 19:38

5 Answers5

29

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!

AnythingIsFine
  • 1,777
  • 13
  • 11
17

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
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
5

Move Chromedriver to path with:

sudo mv -f ~/chromedriver /usr/local/bin/chromedriver

/usr/local/bin/chromedriver is path.

Doan Bui
  • 3,572
  • 25
  • 36
0

For selenium framework (python or java), Browser driver(chrome/firefox/ etc.) should be saved on the Path " /usr/local/bin/chromedriver & /usr/bin/chromedriver"

For Chrome Driver Link : https://chromedriver.chromium.org/downloads go to the link and download the chrome driver for corresponding OS.

Linux: Open the terminal on the Saved/downloaded directory then enter the command

"sudo mv /path/to/chromedriver /usr/bin" "sudo mv /path/to/chromedriver /usr/local/bin"

SThanga
  • 1
  • 1
0

Easiest way would be to download the Google Chrome Driver you prefer and drop in /usr/share/bin directory in Linux.

https://chromedriver.chromium.org/downloads (to download Chrome Driver needed)

sudo mv -v <location_downloaded_chromedriver>/chromedriver /usr/local/bin/.

To make sure Chrome Driver is properly working, you may check the version you just installed as below:

/usr/local/bin/chromedriver -v  #prints you the installed version
Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51