Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WatiN how to wait until postback is complete

Tags:

asp.net

watin

in WatiN how can I wait until postback is complete.

For example:

// Postback response modifies update panel elsewhere on page
browser.Text("id").TypeText("asd"); 

// WatiN doesn't wait until postback is completed (what code should I replace it with?).
browser.WaitUntilComplete();
like image 545
Sergej Andrejev Avatar asked Dec 30 '09 11:12

Sergej Andrejev


3 Answers

You could check if IE is busy rather than complete.

while (((SHDocVw.InternetExplorerClass)(_ie.InternetExplorer)).Busy)
        {
            System.Threading.Thread.Sleep(2000);
        }
like image 116
gingerbreadboy Avatar answered Nov 19 '22 00:11

gingerbreadboy


WaitUntilComplete doesn't recognize ajax calls. See this article (search on WaitForAsyncPostBackToComplete) on how to inject some code to make that work as well: WatiN, Ajax and some Extension Methods

HTH, Jeroen

like image 42
Jeroen van Menen Avatar answered Nov 19 '22 01:11

Jeroen van Menen


As mentioned WaitForComplete is fine for a loading page, but doesn't work for Ajax calls.

Here's a very simple solution that works well for my situation where I expect a specific element to appear... perhaps... eventually. It simply loops until elementID exists on a page, or times out after 20 seconds:

DateTime _startWait = DateTime.Now;
while (_startWait.AddMilliseconds(20000) > DateTime.Now && !WatiNbrowser.Elements.Exists(elementID))
                    {
                        System.Threading.Thread.Sleep(200);
                        Application.DoEvents();
                    }
like image 41
Ben Power Avatar answered Nov 19 '22 01:11

Ben Power