Search code examples
rubybuttonwatirexists

Watir Invisible Button Breaking Ruby Script


I'm using Watir to load a page. It loads items, and has a LOAD MORE button at the bottom if there are further products.

In the HTML the button exists even if there are no more items to load, but it's invisible. So my logic breaks.

Instead of relying on a rescue, how can Watir handle this instead? My current qualifier is the following:

if a.button(class: 'load-more-button action').exist?

It does exist, however in the visible page, the button is hidden because there are no more items to load. Hence confusion.

There is no .visible? method that I can find. So there's a difference between visible and what's always reported as true in the HTML.

Anybody know how I can qualify the presence of this element? Cheers


Solution

  • The #visible? method is now aliased with the #present? method. It will return false if the element does not exist in the DOM, or if it exists but is not displayed on the page.

    https://github.com/watir/watir/blob/v7.1.0/lib/watir/elements/element.rb#L537