Watir 6.6 Released!

Written by: Titus Fortner on August 1, 2017

Watir 6.6.0 is now available on RubyGems! We’ve added several more exciting features.

To install:

gem install watir

or in your Gemfile:

gem "watir", "~> 6.6"


Watir Capabilities

It has long frustrated me that if I want to run Watir on a remote server that I have to initialize long and often unnecessary Selenium classes:

caps = Selenium::WebDriver::Remote::Capabilities.chrome
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
url = "http://localhost:4444/wd/hub"

Watir::Browser.new :remote, {desired_capabilities: caps, http_client: client, url: url}

No more! You never have to specify :remote again. Watir will treat it as remote if you are passing in a URL.

The above code can now be accomplished with:

Watir::Browser.new :chrome, {timeout: 120, url: "http://localhost:4444/wd/hub"}

If you add options when using Selenium::WebDriver::Remote::Capabilities, you can now pass them in as part of the Watir options.

caps = Selenium::WebDriver::Remote::Capabilities.chrome(opts)
Watir::Browser.new :remote, {desired_capabilities: caps}

can be done as this:

Watir::Browser.new :remote, opts

As a special bonus, we’ve also implemented direct support for Chrome’s new headless mode:

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

Note: Chrome Headless still struggles with things like alerts and window switching, but for basic functionality it is working well. Also, headless is only supported on Chrome > 60.


Adjacent Element Locators

In Watir 6.2 we introduced Adjacent Element Location, but we only implemented it with :tag_name and :index locators:

grandparent_table = browser.table.parent(tag_name: 'table', index: 1)

In this release we’ve made it so you can now use any Watir supported locator as a parameter in your adjacent methods:

browser.table.parent(tag_name: 'div', class: ['a', '!b'], text: /foo/, index: 1)


Select Lists

Select lists have been refactored to make fewer wire calls, so you might see some performance improvements if you work with Select Lists that have a large number of options.

Currently Select#select iterates through every single option to see if the option matches the provided value. This is because some Select Lists are capable of selecting multiple options. Since this requires a huge number of wire calls that are unnecessary for most use cases, we are deprecating the use of #select for multiselect Select Lists. It is still supported, but it will throw a deprecation notice. We’ve implemented Select#select_all for you to convert to if you want to select multiple options in a given Select List. This is setting us up for additional performance gains when we move to Watir 7.0 and remove support for things that have been deprecated.


Watir Logger!

This is “very similar” to the recently implemented Selenium::WebDriver::Logger class. You can specify an output other than STDOUT with:

Watir.logger.output = 'watir.log'

By default the level is set to :warn so you will see deprecation notices and any warning messages.

To also see details on each element interaction set the level to info:

Watir.logger.level = :info

To also see what Watir is doing when it converts the selector hash into an XPath, set the level to debug:

Watir.logger.level = :debug

If you have suggestions on what other things you might want to see exposed in Watir Logs, please let us know.


Other Features

  • You can use these methods to minimize the need to call ElementCollection#to_a
    • ElementCollection#locate
    • ElementCollection#empty?
    • ElementCollection#any?
  • Added support to relocate elements that are created with Element#to_subtype
  • Added support to locate buttons with type attribute (Thanks Justin Ko)


See the Changelog for the complete history of updates.