停止加载页面 watir-webdriver

发布于 2024-12-10 15:34:18 字数 106 浏览 0 评论 0原文

有没有办法停止在 Firefox 上使用 watir-webdriver 加载页面?或者有没有办法在我的脚本中强制执行某些操作,即使页面仍在加载?在我的脚本中的某个时刻,网站将挂起并且脚本最终超时。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对你再特殊 2024-12-17 15:34:18

您可以使用 Timeout 类强制它在等待合理时间后放弃(这也是 Watir 内部执行等待的方式)

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

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
柠檬 2024-12-17 15:34:18

如果网站挂起,并且没有出现元素,您应该能够使用 wait 方法使脚本超时。这些主要用作 AJAX 的答案,但它们也应该适用于这种情况。例如,如果脚本在您单击链接后挂起,并且您希望下一页具有特定标题或文本:

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

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

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

其中每个都将等待 30 秒以满足条件,然后退出并出错。您可以更改应用程序挂起窗口内退出的时间 (30)。

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.

殤城〤 2024-12-17 15:34:18

请查看 Selenium 问题 http://code.google.com /p/selenium/issues/detail?id=687 尚未修复,watir-webdriver 也是基于 Selenium 的,希望它能回答您的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文