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

Chrome Options

Note: this documentation has been updated for Watir 6.19, and is focused on supporting the updates made for Selenium 4.

For non-browser specific capabilities take a look at our Capabilities Guide In addition to those, there are a number of Chrome specific settings that will change how Chrome operates during the test run.

Watir will build the options for you when you pass in a Hash that is based on Selenium’s Chrome::Options class

Commonly used settings include:

  • :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
  • :emulation - A Hash for raw emulation options. (it is important to note that the key must be :emulation, not :mobile_emulation)

Preferences

Information on configuring preferences can be found here

Example:

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

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

Arguments

See the full list of switches here

Example:

args = ['--disable-translate']
b = Watir::Browser.new :chrome, options: {args: args}

Headless

Chrome provides a headless mode, which Watir provides access to with a top level capability:

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

Caveats:

  • This isn’t a “full” browser, so not all features may work
  • It is unlikely to speed up your tests by much in most cases
  • If you are using Linux you are likely better off using the headless gem

Last Updated: March 12, 2021