I am running OS X 10.9.4 on my laptop, with Chrome 40.0.2214.94 and Selenium 2.44.0, which I installed for Python 2.7 with easy_install. My code is this basic code from a selenium walkthrough:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
But when I run this I get an exception:
Traceback (most recent call last):
File "/Users/masongardner/Desktop/Selenium_tester.py", line 17, in <module>
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 59, in __init__
self.service.start()
File "/Library/Python/2.7/site-packages/selenium-2.44.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 66, in start
"ChromeDriver executable needs to be available in the path. "
selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
As the documentation specifies, chrome is at this location on my machine:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
What can I do to get around this problem and begin to retrieve data from certain pages as I had planned? If you could be very explicit about code changes or location changes, as I am not the most well versed in computing!
Thanks everyone, and I hope my question isn't too simple!
ChromeDriver is a binary file that interfaces WebDriver with Chrome. If you have WebDriver's libraries installed, and Chrome installed, you still need the ChromeDriver binary in a location that WebDriver can find it.
As the error message indicates, you need to get the binary from here:
http://chromedriver.storage.googleapis.com/index.html
And then place the binary file somewhere on your PATH. Optionally, you can tell WebDriver where the binary is by setting a system property. I would start off by placing the binary somewhere on your PATH and get more specific/complex if you need to.
/usr/bin is on the global path for OS X, so that's a good place to put the file. Plus, it would be available to any user on the computer. You can open up that folder by opening a Finder window, choosing the Go -> Go To Folder in the menu, then entering in /usr/bin (you'll probably be asked for your password as it's a system location.) Then just copy the ChromeDriver binary file into there.
Use '/usr/local/bin/chromedriver'. This worked for me:
import selenium
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = '/usr/local/bin/chromedriver'
browser = webdriver.Chrome(chromedriver)
browser.get('https://stackoverflow.com/users/login')
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