WatiN 搜索谷歌后找不到文本 [英] WatiN can't find text after searching google

查看:22
本文介绍了WatiN 搜索谷歌后找不到文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的等待示例:搜索谷歌然后验证搜索结果.(在 IE9 上)

I'm trying to run a simple watiN example: search google then verify the search result. (on IE9)

var browser = new IE("http://www.google.com/ncr");

browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.Button(Find.ByName("btnG")).Click();

Assert.True(browser.ContainsText("WatiN"));

这个测试失败了!我不知道为什么,但是添加对 WaitUntilContainsText("Everything") 的调用使此通过:

This test fails! I don't know why, but adding a call to WaitUntilContainsText("Everything") make this pass:

var browser = new IE("http://www.google.com/ncr");

browser.TextField(Find.ByName("q")).TypeText("WatiN");
browser.WaitUntilContainsText("Everything");// because of google instant??
browser.Button(Find.ByName("btnG")).Click();

Assert.True(browser.ContainsText("WatiN"));

我猜这可能是因为 google Instant 的行为,但不能确定.有人能解释一下这个测试有什么问题吗?

I guess this maybe because of the behavior of google instant but can't be sure. Can someone explain what's wrong with this test?

推荐答案

是的,这与 Google Instant 有关.当您在按钮上调用 Click() 时,页面将不会重新加载,因此对 ContainsText 的调用几乎不会延迟.如果您正在浏览由 javascript 动态生成的页面(主要是 AJAX),您需要使用 IE 或元素的一些 Wait... 方法.

Yes, it has to do with Google Instant. When you call Click() on button the page will not be reloaded, so the call to ContainsText will occur almost without delay. You need to use some Wait... methods of the IE or elements if you are browsing pages generated by javascript on the fly (AJAX mostly).

这篇关于WatiN 搜索谷歌后找不到文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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