Watir 6.2.0 is now available on RubyGems! Several exciting new features have been added for this release.
or in your Gemfile:
Adjacent Element Location
One of the goals of Watir is to keep users from ever having to write XPath. Why? Because it is difficult to read and difficult to write well enough to avoid brittleness. Until now, accessing adjacent elements required users to write XPath.
Locating Single Elements:
Element#parentreturns the element that exists one level up in the DOM from the base element.
Elementthat exists at the same level in the DOM immediately prior to the base element.
Elementthat exists at the same level in the DOM immediately after the base element.
Elementthat exists one level down in the DOM from the base element.
Locating Element Collections
ElementCollectionof all elements that exists at the same level in the DOM immediately prior to the base element.
ElementCollectionof all elements that exists at the same level in the DOM immediately after to the base element.
ElementCollectionof all elements that exists one level down in the DOM from the base element.
All of these methods accept both
For instance, this code:
Note that index is base 1 here. Assuming this cell is in a nested table,
index: 1 returns the parent
index: 2 returns the grandparent
Either way it skips past all of the
tbody elements to match
No More XPath!
If you’ve ever gotten an
UnknownObjectException with an obscure locator
that’s required you to hunt through a bunch of files trying to figure out
which one is broken, this is the fix. You can now set a keyword on an
element which will show up in the error allowing for easier identification.
Now gives this error:
As of this release,
will have slightly different behaviors. The scenario is when you locate an element by a
specific selector, and while the element itself is still there, the signature by which
you located it has changed. For instance if you locate:
foo = browser.div(class: foo)
In one sense the element object is still there, but the Watir way of evaluating an element
is whatever element is at the provided address, in which case this element no longer exists.
With this update,
Element#wait_while(&:present?) will timeout because it continues
to see the element object; and
Element#wait_while_present will exit because it is
evaluating the selector is as expected and not just the object.
Feel free to ask us on the Watir channel in
Selenium Slack if you have specific questions
about the reasons behind this particular implementation.
See the Changelog for the complete history of updates.