You need to make sure the standalone ChromeDriver binary (which is different than the Chrome browser binary) is either in your path or available in the webdriver.chrome.driver environment variable.
see http://code.google.com/p/selenium/wiki/ChromeDriver for full information on how wire things up.
Edit:
Right, seems to be a bug in the Python bindings wrt reading the chromedriver binary from the path or the environment variable. Seems if chromedriver is not in your path you have to pass it in as an argument to the constructor.
import os
from selenium import webdriver
chromedriver = "/Users/adam/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://stackoverflow.com")
driver.quit()
For Linux
Check you have installed latest version of chrome brwoser-> chromium-browser -version
If not, install latest version of chrome sudo apt-get install chromium-browser
get appropriate version of chrome driver from here
Unzip the chromedriver.zip
Move the file to /usr/bin
directory sudo mv chromedriver /usr/bin
Goto /usr/bin
directory cd /usr/bin
Now, you would need to run something like sudo chmod a+x chromedriver
to mark it executable.
finally you can execute the code.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
Mac OSX only
An easier way to get going (assuming you already have homebrew installed, which you should, if not, go do that first and let homebrew make your life better) is to just run the following command:
brew install chromedriver
That should put the chromedriver in your path and you should be all set.
Download ChromeDriver from this direct link OR get the latest version from this page.
Paste the chromedriver.exe
file in your C:\Python27\Scripts
folder.
This should work now:
from selenium import webdriver
driver = webdriver.Chrome()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With