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条回答
小情绪 Triste *
2楼-- · 2019-03-10 06:30

This is how I wait for AJAX in my project...

ajax_loader = $b.element(:xpath  => "//*[@id='spinner-modal-transparent' and @aria-hidden='true']/div/div/div/div/img[@alt='Ajax transparent loader']")

if ajax_loader.exists?
  ajax_loader.wait_while_present(timeout=350)
else
  puts "The AJAX loader was not present."
end
查看更多
登录 后发表回答