Chrome  

ChromeDriver

To use Chrome, ensure you’re using the appropriate driver

Starting Chrome

Chrome is the default, so you don’t even have to specify it unless you need to add capabilities.

b = Watir::Browser.new
b = Watir::Browser.new :chrome, opts

Headless

Chrome has a new headless feature that can be accessed directly with:

b = Watir::Browser.new :chrome, headless: true

It is still under active development so not all features work yet (alerts, window switching, etc)

Chrome Options

The options hash can be created with the following parameters:

  • :args - an Array of command-line arguments to use when starting Chrome
  • :binary - a String representing the Path to the Chrome Browser executable to use
  • :prefs - a Hash with each entry consisting of the name of the preference and its value
  • :extensions - an Array of Strings listing the paths to (.crx) Chrome extensions to install on startup
  • :options - a Hash for raw options
  • :emulation - A Hash for raw emulation options

Preferences

Information on configuring preferences can be found here

prefs = {
  download: {
    prompt_for_download: false,
    default_directory: '/path/to/dir'
  }
}

b = Watir::Browser.new :chrome, options: {prefs: prefs}

Switches

See the full list of switches here

args = ['--ignore-certificate-errors', '--disable-popup-blocking', '--disable-translate']
b = Watir::Browser.new :chrome, options: {args: args}

Raw Options

See the full list of options here

b = Watir::Browser.new :chrome, options: {options: {detach: true}}

Using chrome on Heroku

You can drive the chrome browser on heroku with a cedar-14 stack. Check out this sample repo for more information on how to do this: https://github.com/jormon/minimal-chrome-on-heroku-xvfb

You can also run using a headless chrome on the heroku-16 stack. Here’s an example of that working: https://github.com/jormon/minimal-chrome-on-heroku

Last Updated: August 03, 2018