Launch Watir/Selenium Chrome driver binary from an arbitrary location

2.1k views Asked by At

I want to use Watir to start a chrome for an older version of chrome, say /Application/Google Chrome 30.app

Here's a ref link saying chromedriver expects Chrome install at specific location:

Mac /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

Here's a ref link for setting up Chrome executable in a non-standard location

ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");

How can I do that using Watir, given syntax like

driver = Watir::Browser.new :chrome

Thanks!

3

There are 3 answers

0
Justin Ko On BEST ANSWER

Set Binary For Specific Browser Instance

The Chrome options can be passed from Watir to Selenium using the :desired_capabilities as "chromeOptions":

caps = {"chromeOptions" => {"binary" => 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'}}
browser = Watir::Browser.new(:chrome, desired_capabilities: caps)

Note about the binary value (from the Chromedriver page):

Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g., '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')

Set Default Binary

Instead of setting the binary for each browser, you can also set the default binary location:

Selenium::WebDriver::Chrome.path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
browser = Watir::Browser.new :chrome
0
djangofan On

My suggestion is not to use WatiR at all and just use the "Selenium bindings" instead. I think the syntax is easier to grok anyways. I would trust the Selenium bindings better, as far as consuming that ChromeOptions binary location parameter.

0
Joshua Pinter On

Update your Selenium driver_path directly.

Just call this before launching your new Chrome browser window:

Selenium::WebDriver::Chrome::Service.driver_path = "/path/to/other/chrome/binary"

Of course, change the path to where your chromedriver is. For us, we used Rails.root.join( "lib", "chromedriver" ).to_s because it's dynamic to the project and we could check this into the repo and it'll just work for all of our engineers.

NOTE: driver_path needs to be a String, so don't pass in a File or Path object.