Reputation: 97
I'm trying to to get Selenium to use Chrome (via gem 'chromedriver-helper') so I can use capybara.
However, I keep encountering this error in irb - Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.
I'm aware Selenium defaults to Firefox and geckodriver, however my iMac no longer gets MacOS updates, so brew won't download geckodriver. So, I'm using chromedriver.
Below is what I have typed in irb.
2.3.3 :001 > require 'capybara/dsl'
=> true
2.3.3 :002 > require 'selenium-webdriver'
=> true
2.3.3 :003 > include Capybara::DSL
including Capybara::DSL in the global scope is not recommended!
=> Object
2.3.3 :004 > Capybara.default_driver = :selenium
=> :selenium
2.3.3 :005 > driver = Selenium::WebDriver.for:chrome
=> #<Selenium::WebDriver::Chrome::Driver:0x3f7ff1cdc18a3184 browser=:chrome>
2.3.3 :006 > visit 'http://capybaraworkout.herokuapp.com'
Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.
I thought the below snippet told Selenium to use Chrome, instead of Firefox!!
driver = Selenium::WebDriver.for:chrome
I'm expecting - visit 'http://capybaraworkout.herokuapp.com' to take me to the URL in chrome (as 'visit' is a capybara method) I know - driver.get 'http://capybaraworkout.herokuapp.com'will take me to the URL, but then when I use another capybara method like - click_link 'Start Workout!' I get the same error (Selenium::WebDriver::Error::WebDriverError: Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.)
What do I need to do, to get Capybara to use Chrome via Selenium?
Upvotes: 1
Views: 1316
Reputation: 49870
You need to register a driver with a specific configuration to tell Capybara to use a different browser - https://github.com/teamcapybara/capybara#configuring-and-adding-drivers. However, if all you want is Selenium using Chrome with a default setup then Capybara already has a driver registered for you - https://github.com/teamcapybara/capybara#selenium
Capybara.default_driver = :selenium_chrome
That will require you to have chromedriver installed (which the chromedriver-helper gem will do for, although I would recommend using the webdrivers
gem instead). If you don't want to use selenium/chromedriver then there are a couple of newer options which talk directly to Chrome, one of which is the appartion
driver - https://github.com/twalpole/apparition
Upvotes: 1