Stop loading page watir-webdriver

徘徊边缘 提交于 2019-11-30 07:41:02

问题


Is there a way to stop loading a page with watir-webdriver on firefox? Or is there a way to force something in my script even if the page is still loading? At a point in my script, the website will hang and the script eventually timeouts.


回答1:


You can use the Timeout class to force it to give up after waiting a reasonable amount of time (and this is internally how Watir performs it's waits as well)

begin
  Timeout::timeout(10) do
    # perform actions that may hang here
  end
rescue Timeout::Error => msg
  put "Recovered from Timeout"
end



回答2:


If the website hangs, you should be able to use a wait method to timeout the script if an element does not appear. These are mainly used as an answer to AJAX, but they should work for this condition as well. For example, if the script hangs after you click a link, and you expect the next page to have a specific title or text:

@browser.link(:name => "Let's Hang!").click
Watir::Wait.until(30) { @browser.title == "new page" }

or

Watir::Wait.until(30) { @browser.text.include? ("confirmation text") }

or

@browser.image(:src => "awesome.jpg").wait_until_present(30)

Each of these will wait 30 seconds for the condition to be met before exiting with an error. You can change the time (30) to exit within your app's hang window.




回答3:


please have a look at the Selenium issue http://code.google.com/p/selenium/issues/detail?id=687 it's not fixed yet, watir-webdriver is also based on Selenium, hope it answers your question.



来源:https://stackoverflow.com/questions/7831290/stop-loading-page-watir-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!