Watir 7.1

Written by: Titus Fortner on November 15, 2021

Watir 7.1.0 is now available on RubyGems. This release re-works a few things related to scrolling.

To install:

gem install watir

or in your Gemfile:

gem "watir", "~> 7.1"

New Method: Element#in_viewport?

This method attempts to determine whether the top of the element is positioned on the page within the browser viewport. It is of limited value for most testing purposes, but it is necessary to support other methods, and there wasn’t a good reason not to make it a public method.

Change to: Element#obscured?

This method attempts to determine if clicking an element will result in a click intercepted error before trying to actually click on the method. Previous behavior was to always scroll the element to the top of the page. For this release the element will only be scrolled if it is determined not to already be in the viewport, and if it is not, it will be scrolled to the bottom of the page to match the correct behavior for clicking an element according to the WebDriver specification.

Automatic Element Scrolling

Per the WebDriver specification, mouse movements when executing action chains are not supposed to scroll the page. If an element is outside the page, it is supposed to raise a “move target out of bounds” error. For most methods that use the actions chains (#double_click, #right_click, #hover, #drag_and_drop_on, and #drag_and_drop_by), Watir has been scrolling the element to the center of the viewport before executing the actions. In this release, we’ve added a :scroll_to parameter that allows you to automatically scroll to :top or :bottom instead of :center. Further, if you do not want Watir to scroll at all, you can pass in nil as the argument.

In addition to the above-mentioned methods, #click also uses action chains when provided modifiers (e.g., :shift, :alt, :control, :command, etc.), but has not been getting automatically scrolled. As of this release this method will also automatically scroll.

See the Changelog for the complete history of updates.

Tags:

Thoughts about this article? Let us know!