Watir 6.3 Released!

Written by: Titus Fortner on June 20, 2017

Watir 6.3.0 is now available on RubyGems! A few fun new features have been added for this release.

To install:

gem install watir

or in your Gemfile:

gem "watir", "~> 6.3"


Locate elements based on presence/absence of an attribute

Let’s say we have these three elements:

    <div data-foo=foo data-bar=bar>element 1</div>
    <div data-foo=foo>element 2</div>
    <div data-foo=bar>element 3</div>


Previously, in order to locate the second element you would need to use an index:

browser.div(data_foo: 'foo', index: 1).text
# => 'element 2'


Now you can use the fact that data-bar is not present:

browser.div(data_foo: 'foo', data_bar: false).text
# => 'element 2'


Or say you want to get a collection of everything that has a specific attribute, regardless of what the value is. It used to be the only way to accomplish this was with regular expressions. Now you can use the much more readable syntax:

browser.divs(data_foo: true).size
# => 3


Element Flash Attributes

Watir has long supported the ability to make a located element flash on the screen (useful for debugging or demonstrations). Now you can specify:

  • the color the element will flash (default is red)
  • the number of times the element will flash (default is 10)
  • the delay in seconds between flashes (default is 0)

For example:

browser.div(id: "waldo").flash(color: "green", delay: 0.5, flashes: 3)
# => 3


Select List text

For a Select List like this:

<select id="foo">
 <option value="1">Option 1</option>
 <option value="2" selected="selected">Option 2</option>
</select>

Watir has long allowed getting the value of the selected option like this:

browser.select(id: 'foo').value
# => 2

Now you can also get the text of the selected option the same way:

browser.select(id: 'foo').text
# => Option 2


Thanks

Big thanks to three new Watir committers for their contributions to this release:


See the Changelog for the complete history of updates.

Tags: