WatiN can't find text after searching google

て烟熏妆下的殇ゞ 提交于 2019-12-11 02:18:59

问题


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"));

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"));

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?


回答1:


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).



来源:https://stackoverflow.com/questions/5816267/watin-cant-find-text-after-searching-google

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