54

I am trying to execute some tests using chromedriver and have tried using the following methods to start chromedriver.

driver = webdriver.Chrome('/usr/local/bin/chromedriver')

and

driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

and

import os
from selenium import webdriver

chromedriver = "/usr/local/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")

But none of these seems to help and the error is : selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.

I have checked multiple times and chromedriver is present in location /usr/local/bin.

Still my scripts are not working. Could any body pls help.

My google-chrome location is : /usr/bin/google-chrome

Saheb
  • 1,666
  • 3
  • 18
  • 24
  • 1
    Make sure the chromedriver binary is available in the provided path and not the directory which contains chromedriver.exe – Amith Mar 18 '14 at 10:42
  • This is the location of binary, not the directory. @Amith – Saheb Mar 18 '14 at 11:07
  • i have already answered it in another question [selenium/python/ubuntu](http://stackoverflow.com/questions/22130109/cant-use-chrome-driver-for-selenium/44039546#44039546) – Shinto Joseph May 20 '17 at 04:59
  • For Debian/Ubuntu - it works: see the below link [chrome-webdriver for selenium/python/ubuntu ](http://stackoverflow.com/questions/22130109/cant-use-chrome-driver-for-selenium/44039546#44039546) – Shinto Joseph May 20 '17 at 05:04
  • @ShintoJoseph, so it doesn't respect PATH in any way? – Velkan Mar 01 '18 at 15:56

10 Answers10

80

Following the suggestion from https://askubuntu.com/questions/539498/where-does-chromedriver-install-to I was able to make it work like this:

  1. Installed the chromium-chromedriver:

    sudo apt-get install chromium-chromedriver
    
  2. Adding the path to the selenium line:

    driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
    

Note that this opens Chromium and not Chrome. Hope it was helpful.

Community
  • 1
  • 1
Zamfir Stefan
  • 809
  • 6
  • 3
  • 2
    Worked for me perfectly – Renato Francia Jan 15 '21 at 03:35
  • 2
    I've tried plenty of advices (e.g. setting --no-sandbox, --disable-dev-shm-usage, using WebDriver Manager, I even snap-aliased chromium to google-chrome). This worked even with chromium version 102.x.y. – Emil Jun 21 '22 at 09:30
10

I have solved the issue in the following way:

  1. Open a terminal and type whereis chromedriver. In my case, I had the following output:

    chromedriver: /usr/local/bin/chromedriver

  2. Copy that path and edit your Webdriver instance like:

driver = webdriver.Chrome('/usr/local/bin/chromedriver')

That should be enough!

Javier Sorella
  • 151
  • 1
  • 5
5

The following should normally work:

driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')

Note that in your question there was no preceding '/' in the path.

Additionally, make sure that the chromedriver executable located in /usr/local/bin/ has appropriate file permissions, i.e. that it can be executed:

> chmod 777 /usr/local/bin/chromedriver
Tytus
  • 640
  • 6
  • 5
  • 1
    I have changed chmod to 777 and have already used the preceeding '/' [edited]. Still the same error. @Tytus – Saheb Mar 18 '14 at 11:07
  • This approach worked for me. All the above approaches did not work on their own....I first needed to change permissions and then `executable_path` worked. – edesz Jan 23 '20 at 20:35
2

As the message says: ChromeDriver executable needs to be available in the path.

So is it in the path? What is the output of:

$ cd
$ chromedriver --version

If you don’t see the version, chromedriver is definitively not in the PATH.

I don’t tell webdriver where to find chromedriver otherwise. – I use the Ubuntu package “chromium-chromedriver”, but it drops the binary in /usr/lib/chromium-browser/chromedriver, which is not in my PATH. So I put a soft link in /usr/bin.

Robert Siemer
  • 32,405
  • 11
  • 84
  • 94
2

Most probably you have not complete installing the chrome driver. I suggest you to install this with apt, Because apt installs all dependencies itself. The other answers are true; but in the last versions which installed "chromium-browser". but now this name is changed to "chromium-driver". so you shoulde install this:

apt-get install chromium-driver

this driver will be installed in /usr/bin and this name will be "chromedriver" so for import path to selenium use this path: /usr/bin/chromedriver:

driver = webdriver.Chrome('/usr/bin/chromedriver')
Tapan Hegde
  • 1,222
  • 1
  • 8
  • 25
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 03 '21 at 10:03
2

It is enough to point out to the Chrome Browser driver on your machine. If you already have Chromium browser installed, then search for the driver:

sudo find / -type f -name chromedriver

then select the driver corresponding to your browser.

PS: for me it was

driver = webdriver.Chrome('/snap/chromium/1827/usr/lib/chromium-browser/chromedriver')
alv2017
  • 752
  • 5
  • 14
1

For Mac users:

  1. brew install chromedriver.
  2. After installation ==> Linking Binary 'chromedriver' to '/usr/local/bin/chromedriver' will popup.
  3. From now on, you should be able refer to /usr/local/bin/chromedriver in the code.
  4. You might face Selenium Python: No such file or directory: '/usr/local/bin/chromedriver' but it exists and is added to path and/or Error message: "'chromedriver' executable needs to be available in the path". It's because brew install cask is required as well, as explained in https://www.kenst.com/2015/03/installing-chromedriver-on-mac-osx/.
  5. Again an error FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/bin/chromedriver'? Try brew reinstall chromedriver and it was the first time brew reinstall chromedriver (got from Using Selenium on Mac Chrome) returned something different than chromedriver not found. Namely, /usr/local/bin/chromedriver :)
  6. The last issue I was facing was “chromedriver” cannot be opened because the developer cannot be verified. popup whenever I've tried to run the script. cd /usr/local/bin, then xattr -d com.apple.quarantine chromedriver (credits: MacOS Catalina(v 10.15.3): Error: “chromedriver” cannot be opened because the developer cannot be verified. Unable to launch the chrome browser) solves the problem, and the ChromeDriver finally ran.
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
0

You need to make sure the standalone ChromeDriver binary is either in your path or available in the webdriver.chrome.driver environment variable and then try to use absolute path to that binary. Below is the code for java -

    File chromeDriver = new File("/usr/bin/chromedriver");
    System.setProperty("webdriver.chrome.driver", chromeDriver.getAbsolutePath());
    driver = new ChromeDriver();
Dev
  • 36
  • 3
0

Just pass the binary location as argument to it and not just the directory conatining it. So if it lies in /usr/bin directory, then run below command:

driver = webdriver.Chrome("/usr/bin/chromedriver")

This worked for me in ubuntu and adding path to bashrc is not working. Give it a try.

amritkrs
  • 632
  • 7
  • 12
0

hope this will be useful for some who did like me. For my case i left preceding slash in the path did "home/user/chromedriver" instead of "/home/user/chromedriver"

Janarthanan Ramu
  • 1,331
  • 16
  • 17