Alex Rivera | Logout

C# how to wait for a webpage to finish loading before continuing

Asked 2009-02-24T22:25:58.773
35

I'm trying to create a program to clone multiple bugs at a time through the web interface of our defect tracking system. How can I wait before a page is completely loaded before I continue?

//This is pseudo code, but this should give you an idea of what I'm trying to do.  The
//actual code uses multi-threading and all that good stuff :).
foreach (string bug in bugs)
{
    webBrowser.Navigate(new Uri(url));
    webBrowser.Document.GetElementById("product").SetAttribute("value", product);
    webBrowser.Document.GetElementById("version").SetAttribute("value", version);
    webBrowser.Document.GetElementById("commit").InvokeMember("click");

    //Need code to wait for page to load before continuing.
}
Edit
Report

2 Answers

2

Have a go at Selenium (http://seleniumhq.org) or WatiN (http://watin.sourceforge.net) to save yourself some work.

answered 2009-02-24T22:45:54.967
1

I think the DocumentCompleted event of the WebBrowser control should get you where you need to go.

answered 2009-02-24T22:29:45.240

Your Answer