Search code examples
webdriverwatirfirewatirsafariwatir

How to use watir-webdriver to wait for page load


Using watir-webdriver, how do I wait for a page to load after I click a link?

At the moment I am using:

sleep n

But this is not ideal as the page response varies so much.

Is there a way to test whether the page is ready or whether there is a certain element in the page? I understand in the normal Watir gem there is Watir::Waiter.wait_until or something similar, but I don't see this in the webdriver version.


Solution

  • I don't know if they're the best way, but this is how I'm handling this for waiting for an updating div to clear:

    while browser.div(:id=>"updating_div").visible? do sleep 1 end
    

    This is how I handle waiting for something to display:

    until browser.div(:id=>"some_div").exists? do sleep 1 end