Can't use chrome driver for Selenium

痞子三分冷 提交于 2019-11-27 12:05:33

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


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

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

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

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)
Shinto Joseph

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

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

Chrome

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

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")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!