cucumberwatirwatir-webdriverpageobjectsbrowser-testing

Watir: Always wait when webpage element present


A web application consistently uses this div after user actions. My test scripts have this line. verbatim, all over the place.

@browser.div(:id => 'loading-indicator').wait_while_present

Explicitly including this line everywhere is OK, but ugly and repetitive.

Using wait_until_present with the next element ("foo") after the loading indicator would sometimes work. However, in some cases foo and the loading indicator are present simultaneously, but foo is not visible? until the loading indicator disappears.

Is there a way, perhaps in env.rb, to indicate to watir-webdriver that it should always wait_while this element is present?


Solution

  • If you want to check for it after every click and page load/reload you can add it to an After Hook

    browser.after_hooks.add do |b| 
      b.div(id: 'loading-indicator').wait_while_present
    end