Can't use chrome driver for Selenium

Question:

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:Python33libsubprocess.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:Python33libsite-packagesseleniumwebdriverchromeservice.py", line 63, in start
    self.service_args, env=env, stdout=PIPE, stderr=PIPE)
  File "C:Python33libsubprocess.py", line 817, in __init__
    restore_signals, start_new_session)
  File "C:Python33libsubprocess.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:Python33libsite-packagesseleniumwebdriverchromewebdriver.py", line 59, in __init__
    self.service.start()
  File "C:Python33libsite-packagesseleniumwebdriverchromeservice.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.

Asked By: user2540748

||

Answers:

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

driver = webdriver.Chrome(executable_path=r"C:Chromechromedriver.exe")
Answered By: falsetru

Chrome

import os   
from selenium import webdriver
chromedriver = "C://chromedriver.exe"                                                                     
os.environ["webdriver.chrome.driver"] = chromedriver                      
driver =webdriver.Chrome(chromedriver)
Answered By: Prashanth Sams

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()
Answered By: Vicky

For windows

Download webdriver from:

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

Paste the chromedriver.exe file in “C:Python27Scripts” Folder.

This should work now.

from selenium import webdriver
driver = webdriver.Chrome()
Answered By: Abdul Majeed

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

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

Note the r in front of the “C:Chromechromedriver.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")
Answered By: Daan

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)
Answered By: Harshdeep Singh

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")
Answered By: Amit Kumar

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/')
Answered By: Shinto Joseph

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")
Answered By: user8167727
import os
from selenium import webdriver
chromedriver = "C:Driverschromedriver_win32chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
driver =webdriver.Chrome(chromedriver)
driver.get("https://www.facebook.com")
print(driver.title)
driver.close()
Answered By: venkatesh kotagiri

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:Usersnamevirtual_workspaceScripts

from selenium import webdriver
wbdriver = webdriver.Chrome()
Answered By: astuscore

This code doesn’t need path to drive file:

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

    driver = webdriver.Chrome(ChromeDriverManager().install())
Answered By: Giang Hoàng Khánh