使用 WatiN 等待页面完全加载 [英] Waiting for page to be fully loaded using WatiN

查看:34
本文介绍了使用 WatiN 等待页面完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个与同一问题相关的问题...Q1) 我正在使用 WatiN(3.5) 来实现网站的自动化.情况是我想在结果页面完全加载时获得一个 div 标记,但 WatiN 不等待该页面被完全加载并尝试获取该 div,从而导致获得 div空值.此 div 由 AJAX 填充.这是我用来避免该错误的代码,但它不起作用.

I have two questions related to the same problem... Q1) I am using WatiN(3.5) for automation of a website. The situation is that I want to obtain a div tag when the result page is fully loaded but WatiN don't wait for that page to be campletely loaded and tries to obatin that div which results in getting div with null. This div is populated by AJAX. This is th code that I am using to avoid that error but it does not work.

  while (resultDiv == null)
            {
                browser.Div("ui-tabs-1").WaitUntilExists();
                resultDiv = browser.Div("ui-tabs-1"); 
            }

那么如何使用 WatiN 等待页面完全加载?

So how I can wait for a page to be completely loaded by using WatiN?

Q2) 我找到了上述问题的解决方案 here 但我陷入了困境,因为我找不到这些接口的库参考,即 IElementIBrowser.这些接口在扩展方法中使用.我也问过那篇文章的作者,等他回复.我正在 VS 2010 中通过使用 WatiN 2.5 和 .Net framework 3.5 进行此应用.

Q2) I found a solution for above problem here but I stuck at a point as I could not find a reference of library for these interfaces i.e. IElement and IBrowser. These interfaces are bring used in the extension methods. I have also asked the author of that article and waiting for his reply. I am making this apllication by usng WatiN 2.5 and .Net framework 3.5 in VS 2010.

推荐答案

我在使用 Ajax 的站点上遇到了与 watin 类似的问题.这是解决此问题的方法.

I have ran into similar problem with watin on a site using Ajax. This is the workaround for this.

//点击链接/Tab/Button 后,在非 Ajax 网站中加载结果.我们这里有一个函数,browser.WaitForComplete() 但它只有在页面处于加载状态时才起作用.但是如果浏览器窗口的一部分上的 Ajax 被更新.所以浏览器没有加载状态.

//After click on link/Tab/Button on which the result is loaded in non Ajax websites. We have a function here, browser.WaitForComplete() but it works only when the page is in loading state. but in case of Ajax on a part of browser window gets updated. so no loading state for browser.

所以这个问题的一个解决方案是使用 Thread.Sleep(10000); 这个时间可能会随着网站加载所需 div 的正常时间而变化.

So one solution for this problem is Use Thread.Sleep(10000); This time can vary upon the normal time the website takes to load the required div.

这篇关于使用 WatiN 等待页面完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆