I am writing a program that loads a web page then get data from the page for calculations. I can navigate to the web page but the code does not wait for the page to completely load before proceeding. I need a way to have the program wait for the page to load before proceeding.

any ideas?

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'Your Code here, the code will be executed after the page is complete loading
End Sub

I tried your suggestion. I created a form1 that has a web browser and 2 buttons. when I press button 2, I navigate to a web site. when I press button 2 the fields on the website are filled in. If I add your suggestion to button 1 so that the code will wait for the page to load, I get an error in my implementation.

When I call the sub WebBrowser1_DocumentCompleted and pass the values for my webBrowser and arguments with the following :
Call WebBrowser1_DocumentCompleted(instance, L)
I don't know what value to assign to L. My entire code follows:

Public Class Form1

    WithEvents instance As New WebBrowser
    Public Event test As WebBrowserDocumentCompletedEventHandler


    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles instance.DocumentCompleted
        Dim value As WebBrowserReadyState
        Dim Name1 As String
        Dim email1 As String
        Dim comment1 As String
        comment1 = "This is a test"
        Name1 = "My Name"
        email1 = "My.Name@cox.net"
        value = WebBrowser1.ReadyState
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            WebBrowser1.Document.All("name").SetAttribute("value", Name1)
            WebBrowser1.Document.All("email").SetAttribute("value", email1)
            WebBrowser1.Document.All("comments").SetAttribute("value", comment1)



            'WebBrowser1.Document.Forms(0).InvokeMember("submit")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim GetSite As New WebBrowser1
        Dim value As WebBrowserReadyState
        Dim Name1 As String
        Dim email1 As String
        Dim comment1 As String
        comment1 = "This is a test"
        Name1 = "My Name"
        email1 = "my.name@cox.net"
        value = WebBrowser1.ReadyState
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            WebBrowser1.Document.All("name").SetAttribute("value", Name1)
            WebBrowser1.Document.All("email").SetAttribute("value", email1)
            WebBrowser1.Document.All("comments").SetAttribute("value", comment1)



            'WebBrowser1.Document.Forms(0).InvokeMember("submit")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim L As WebBrowserDocumentCompletedEventArgs

        With WebBrowser1
            .Navigate("http://sugarsandsphotography.com/Contact_us.html")
            .Show()

        End With
        Call WebBrowser1_DocumentCompleted(instance, L)

    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.