watir-webdriver wait for page load

2019-03-10 05:59发布

Using 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 there a method 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 cannot see this in the webdriver version.

7条回答
Evening l夕情丶
2楼-- · 2019-03-10 06:13

you can use wait_until....

or

waituntilExists methods

查看更多
forever°为你锁心
3楼-- · 2019-03-10 06:19

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 the page on AJAX and waiting for elements in the Watir-webdriver Wiki

查看更多
我想做一个坏孩纸
4楼-- · 2019-03-10 06:20

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

查看更多
smile是对你的礼貌
5楼-- · 2019-03-10 06:21

I meet the same problems with you, and I try to fix it by combing wait_until_present method and the until browser.div(:id=>"some_div").exists? do sleep 1 end tricks povided by @marc:

some_div = browser.div(:id => 'some_div')

begin 

  Watir::Wait.until
    some_div.visible?
  end

rescue Watir::Wait::TimeoutError

  until some_div.visible?
    sleep 1
  end
end

And be noticed that it is your own responsibility to make sure that the div(:id => "some_div") do exist

查看更多
Rolldiameter
6楼-- · 2019-03-10 06:22

The best summary is found here: http://watir.com/guides/waiting/

Here it is in a nutshell:

require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
b.select_list(:id => 'entry_1').wait_until_present
b.text_field(:id => 'entry_0').when_present.set 'your name'
b.button(:value => 'Submit').click
b.button(:value => 'Submit').wait_while_present
Watir::Wait.until { b.text.include? 'Thank you' }
查看更多
贪生不怕死
7楼-- · 2019-03-10 06:27

browser.wait_until method can be used its more helpful you can define what to wait for in () as browser.wait_until(browser.text.include("some text"))

查看更多
登录 后发表回答