停止加载页面 watir-webdriver
有没有办法停止在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Timeout 类强制它在等待合理时间后放弃(这也是 Watir 内部执行等待的方式)
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)
如果网站挂起,并且没有出现元素,您应该能够使用 wait 方法使脚本超时。这些主要用作 AJAX 的答案,但它们也应该适用于这种情况。例如,如果脚本在您单击链接后挂起,并且您希望下一页具有特定标题或文本:
或
或
其中每个都将等待 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:
or
or
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.
请查看 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.