views:

930

answers:

5

We're using WatiN for testing our UI, but one page (which is unfortunately not under our teams control) takes forever to finish loading. Is there a way to get WatiN to click a link on the page before the page finishes rendering completely?

+2  A: 

Hi Glenn,

The time Watin waits is controlled by the WaitForLoadTimeout property. Here's a blog post which talks a little bit about it:

http://blog.agilejedi.com/2008/08/watin-installed.html

Cory Foy
+1  A: 

@Cory: Unfortunately it's not that WatiN isn't waiting long enough, it's that it waits until the page loads before it does anything.

We found the solution, load the page with ClickNoWait() Then look for the link on the page as normal, but call WaitUntilExists() on the link before calling Click(). This way WatiN will click the link as soon as it is loaded, not wait until the whole page is loaded.

Glenn Slaven
+3  A: 

Here's the code we found to work:

IE browser = new IE(....);
browser.Button("SlowPageLoadingButton").ClickNoWait();
Link continueLink = browser.Link(Find.ByText("linktext"));
continueLink.WaitUntilExists();
continueLink.Click();
Glenn Slaven
+1 for answering yourself to your question ;) And good answer!
tsocks
A: 

@Glenn I was thinking that you would lower the wait time using that, not that the page wasn't waiting long enough. Your way seems much more elegant.

Cory Foy
If I understand how it works correctly, lowering the wait time would just cause the script to fail after the time had expired. I probably have that wrong though
Glenn Slaven
A: 

Hi Glenn,

You should be able to leave out the call to WaitUntilExists() since WatiN does this internally when you call a method or property on an element (like the link.Click() in you rexample).

HTH, Jeroen van Menen Lead dev WatiN

But I'm not calling click, I'm calling ClickNoWait() doesn't that mean that it won't wait unless I call WaitUntilExists()?
Glenn Slaven