views:

499

answers:

4

using watir-webdriver [ http://github.com/jarib/watir-webdriver ]

how do i wait for a page to load after i click a link?

at the moment i am doing

sleep n

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

is their a method to test whether the page is ready or whether their 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 cannot see this in the webdriver version.

+2  A: 

I don't know if they're the best way, but this is how I'm handling this for waiting for 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

marc
cool this works perfectly in firefox, not so great in chrome.i've gone with: sleep 1 until browser.div(:foo => 'bar').exists?
sfusion
The above method is not recommended because it may never return and lock up your scripts (javascript error, code change, etc.). Watir::Waiter.wait_until(15) { browser.div(:id => "updating_div).visible? }
JEH
A: 

Did you read How to wait with Watir?

Željko Filipin
A: 

you can use wait_until....

or

waituntilExists methods

puzzle
+1  A: 

Today's release adds an optional require that brings in some helpers for waiting for elements. These are not (at the moment) available in Watir 1.6, so be aware if you use both libraries side by side.

Check the first question in the watir-webdriver FAQ.

jarib