In some cases (e.g. automation testing) you might need to block current thread execution and wait until web page is loaded completely.


You can use the FinishLoadingFrameEvent to be informed when the main frame is loaded. At this point, you can assume that the page is loaded completely and execute JavaScript, work with DOM, etc.


The following sample code demonstrates how to load http://www.google.com web page and wait until it's loaded completely:

 C#

ManualResetEvent waitEvent = new ManualResetEvent(false);
browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
{
    // Wait until main document of the web page is loaded completely.
    if (e.IsMainFrame)
    {
        waitEvent.Set();
    }
};
browser.LoadURL("http://www.google.com");
waitEvent.WaitOne();

VB.NET

Dim waitEvent As New ManualResetEvent(False)
AddHandler browser.FinishLoadingFrameEvent, Sub(sender, e)
                               If (e.IsMainFrame) Then
                                 waitEvent.Set()
                               End If
                             End Sub
browser.LoadURL("http://www.google.com")
waitEvent.WaitOne()