Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Chromedriver to PATH in linux?

Tags:

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

like image 792
user7188934 Avatar asked Jan 11 '18 18:01

user7188934


People also ask

How do I add a Chrome driver to my path?

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.

How do I run Chrome drivers on Linux?

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.


2 Answers

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!

like image 200
AnythingIsFine Avatar answered Sep 20 '22 11:09

AnythingIsFine


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 
like image 34
Francesco Borzi Avatar answered Sep 22 '22 11:09

Francesco Borzi