user2540748
user2540748

Reputation:

Can't use chrome driver for Selenium

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.

Upvotes: 36

Views: 159572

Answers (12)

Vicky
Vicky

Reputation: 5136


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:
    latest https://googlechromelabs.github.io/chrome-for-testing
    older 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()

Upvotes: 36

This code doesn't need path to drive file:

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

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

Upvotes: 0

astuscore
astuscore

Reputation: 1

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()

Upvotes: 0

venkatesh kotagiri
venkatesh kotagiri

Reputation: 1

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()

Upvotes: 0

Shinto Joseph
Shinto Joseph

Reputation: 3093

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/')

Upvotes: 2

Prashanth Sams
Prashanth Sams

Reputation: 21129

Chrome

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

Upvotes: 0

user8167727
user8167727

Reputation:

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")

Upvotes: 2

Amit Kumar
Amit Kumar

Reputation: 1

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")

Upvotes: -3

Harshdeep Singh
Harshdeep Singh

Reputation: 337

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)

Upvotes: 2

Daan
Daan

Reputation: 49

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")

Upvotes: 4

Abdul Majeed
Abdul Majeed

Reputation: 2781

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()

Upvotes: 8

falsetru
falsetru

Reputation: 368894

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")

Upvotes: 63

Related Questions