Reputation: 339
I'm trying to get Selenium working, but I can't seem to figure it out. I've installed the proper Ruby gem, and am trying to execute this code.
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
driver.navigate.to "http://google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit
I'm fairly certain my issue is that I haven't connected the ChromeDriver correctly. How do I link Chrome driver in order to get this to work? It says I need to place it on my PATH. Can someone explain this?
Also, here is the error I'm getting:
in `executable_path': Unable to find the chromedriver executable.
Upvotes: 2
Views: 2383
Reputation: 1467
Unable to find the chromedriver executable :
We get this when system is not able to locate chromedriver. We can help system find it by setting environment variable "webdriver.chrome.driver"
If you are running unix/linux use
export webdriver.chrome.driver=<path_where_binary_is_present>
If running on windows :
Go to System Advanced Environment Variables. Add an entry with name webdriver.chrome.driver and value set to path of binary
We can also set this location from program also. Like in java System.setProperty("webdriver.chrome.driver", ""
Do any one of this and this error should go away
Upvotes: 0
Reputation: 7421
Place chrome driver depends on your operating system, check this link:
OS Expected Location of Chrome Linux /usr/bin/google-chrome1 Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome Windows XP %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
Upvotes: 0
Reputation: 23835
There is a Selenium::WebDriver::Chrome.driver_path=
method that allows specifying of the chromedriver executable:
# Specify the driver path
Selenium::WebDriver::Chrome.driver_path = "path/to/chromedriver.exe"
# now instantiate chrome driver
driver = Selenium::WebDriver.for :chrome
driver.navigate.to "http://google.com"
element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit
puts driver.title
driver.quit
Upvotes: 4