35

I'm having trouble using the Chrome driver for Selenium. I have the chromedriver downloaded and saved to C:\Chrome:

driver = webdriver.Chrome(executable_path="C:/Chrome/")

Using that gives me the following error:

Traceback (most recent call last):
  File "C:\Python33\lib\subprocess.py", line 1105, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\service.py", line 63, in start
    self.service_args, env=env, stdout=PIPE, stderr=PIPE)
  File "C:\Python33\lib\subprocess.py", line 817, in __init__
    restore_signals, start_new_session)
  File "C:\Python33\lib\subprocess.py", line 1111, in _execute_child
    raise WindowsError(*e.args)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Wilson/Dropbox/xxx.py", line 71, in <module>
    driver = webdriver.Chrome(executable_path="C:/Chrome/")
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
    self.service.start()
  File "C:\Python33\lib\site-packages\selenium\webdriver\chrome\service.py", line 68, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://chromedriver.storage.googleapis.com/index.html  

Any help would be appreciated.

Ratmir Asanov
  • 5,433
  • 5
  • 20
  • 36

12 Answers12

61

You should specify the executable file path, not the directory path that contains the executable.

driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")
falsetru
  • 314,667
  • 49
  • 610
  • 551
  • 1
    Worked like a charm for Mac without the .exe estension – Jaqueline Passos Sep 08 '17 at 18:31
  • hi there - whats the difference between `driver = webdriver.Chrome(executable_path="C:/Chrome/")` and this one `driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")` Note: i work on Win10 - i have issues with the chromedriver too - so i am working on the same things - look forward to hear from you – zero Jun 24 '20 at 16:35
  • @zero, Sorry, I don't have an access to windows 10 machine. Please post a separated question so that others with windows machine can answer you. – falsetru Jun 24 '20 at 21:57
36


For Linux

1. Check you have installed latest version of chrome browser-> "chromium-browser -version"
2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
3. Get the appropriate version of chrome driver from http://chromedriver.storage.googleapis.com/index.html
4. Unzip the chromedriver.zip
5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
6. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.
7. finally you can execute the code.

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
display.stop()
Jared Forth
  • 1,418
  • 5
  • 13
  • 28
Vicky
  • 4,746
  • 2
  • 28
  • 30
  • Isn't chromedriver should be put under /usr/local/bin directory in Ubuntu instead of /usr/bin ? please clarify – vikramvi Feb 08 '18 at 11:22
  • 1
    @vikramvi it doesn't matter as long as the directory is on your path – Corey Goldberg Apr 11 '18 at 12:05
  • @CoreyGoldberg I will prefer to put under default directory instead of custom directory – vikramvi Apr 12 '18 at 04:56
  • good evening dear Viky - many thanks for the great answer. BTW - one question left: hi there - whats the difference between `driver = webdriver.Chrome(executable_path="C:/Chrome/")` and this one `driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")` Note: i work on Win10 - i have issues with the chromedriver too - so i am working on the same things - look forward to hear from you – zero Jun 24 '20 at 16:36
  • before installing latest version of chromium-browser make sure that you have the latest version of google chrome itself with >sudo apt install google-chrome-stable – Victor Di Nov 19 '20 at 12:08
7

For windows

Download webdriver from:

http://chromedriver.storage.googleapis.com/2.9/chromedriver_win32.zip

Paste the chromedriver.exe file in "C:\Python27\Scripts" Folder.

This should work now.

from selenium import webdriver
driver = webdriver.Chrome()
Abdul Majeed
  • 2,275
  • 18
  • 25
3

In addition to the selected answer (windows style path):

driver = webdriver.Chrome(executable_path=r"C:\Chrome\chromedriver.exe")

Note the r in front of the "C:\Chrome\chromedriver.exe", this makes this string a raw string.

In case you do not want to use a raw string you should escape the slash like so \\, this would become:

driver = webdriver.Chrome(executable_path="C:\\Chrome\\chromedriver.exe")

Or you can replace the \ with a /, you will get this:

driver = webdriver.Chrome(executable_path="C:/Chrome/chromedriver.exe")
Daan
  • 39
  • 3
2

When you call selenium or any testing automation library, you would need to add this the code here is in Python but this can be done in Java and Ruby as well.

options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/chromium-browser'
#All the arguments added for chromium to work on selenium
options.add_argument("--no-sandbox") #This make Chromium reachable
options.add_argument("--no-default-browser-check") #Overrides default choices
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps") 
driver = webdriver.Chrome('/home/travis/virtualenv/python2.7.9/chromedriver',chrome_options=options)
RamenChef
  • 5,533
  • 11
  • 28
  • 39
Harshdeep Singh
  • 298
  • 4
  • 17
2

For Debian/Ubuntu - it works:

install Google Chrome for Debian/Ubuntu:

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-
stable_current_amd64.deb

sudo dpkg -i google-chrome*.deb
sudo apt-get install -f

Install ChromeDriver:

wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
chmod +x chromedriver

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver

Install Selenium:

pip install -U selenium

Selenium in Python:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.google.co.in/')
Corey Goldberg
  • 53,391
  • 24
  • 118
  • 137
Shinto Joseph
  • 1,713
  • 15
  • 19
2

All you need to do is Paste the Chromedriver.exe in python36-32 folder.And you can use It Simply like:

from selenium import webdriver
driver = webdriver.Chrome()

No need to paste path again and again.

OR
You can Use:

driver = webdriver.Chrome(executable_path="C:/Chrome/chromedriver.exe")
0

Chrome

import os   
from selenium import webdriver
chromedriver = "C://chromedriver.exe"                                                                     
os.environ["webdriver.chrome.driver"] = chromedriver                      
driver =webdriver.Chrome(chromedriver)
Community
  • 1
  • 1
Prashanth Sams
  • 12,937
  • 16
  • 80
  • 106
0
import os
from selenium import webdriver
chromedriver = "C:\Drivers\chromedriver_win32\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver =webdriver.Chrome(chromedriver)
driver.get("https://www.facebook.com")
print(driver.title)
driver.close()
  • 1
    Can you add some further information as to how this helps solve the initial question? – Tom Oct 15 '19 at 15:24
  • 2
    While this code may solve the question, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Dave Oct 15 '19 at 16:17
0

For Windows with virtual workspace

First, check your browser version: go to 3 dons most right corner of the chrome browser and click it, then, --> Help-->About Google Chrome

once you identify our browser version, we have to download and install chrome drive from this link

extract the zip folder and past chromedriver.exe file in C:\Users\name\virtual_workspace\Scripts

from selenium import webdriver
wbdriver = webdriver.Chrome()
0

This code doesn't need path to drive file:

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

    driver = webdriver.Chrome(ChromeDriverManager().install())
-2

Just place the chromedriver.exe in your python folder (in my case: C:\Python27) and use the below mentioned code it will work for you guys

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("URL")