dcsimg
Results 1 to 5 of 5

Thread: Simple browser login

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Simple browser login

    I am new to .net so bear with me!

    I have WebBrowser1 and this code on a button:

    Code:
    WebBrowser1.Navigate(URLBox.Text)
    That all works fine and I can enter text and go to the webpage.

    How do I:

    1. Check for when the page has finished loading?

    2. Auto populate 2 fields on the webpage and click login?

    Thanks,

    Jon
    Last edited by Jon12345; Dec 17th, 2010 at 10:36 AM.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Simple browser login

    You can use the DocumentCompleted event to let you know when the page has finished loading. And the code below shows you how to populate values and click buttons in web pages. This example, puts a search phrase into google and clicks the I'm feeling lucky button:

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    
            WebBrowser1.Document.All("q").SetAttribute("value", "vbforums")
            WebBrowser1.Document.All("btnI").InvokeMember("Click") 'Click I'm feeling lucky button
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            WebBrowser1.Navigate("http://www.google.com")
        End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Simple browser login

    Thanks for that.

    What if you have an app which has many web purposes. You wouldn't want to have the DocumentCompleted event trigger that code would you? For example, you might want it to allow you to navigate to many pages. Then, when you click a Login button it will navigate to a specific page and enter the form data.

    To my mind, that could only effectively be achieved using a sequential type coding. e.g. when you click the login button, the app waits for the page to load in a loop.

    Your thoughts? How would I do that?

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Simple browser login

    You could use an enum to keep track of your state:

    Code:
        Enum CurrentState
            BeforeVBF
            OnVBF
            AfterVBF
            Done
        End Enum
    
        Dim myState As CurrentState
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    
            Select Case myState
                Case CurrentState.BeforeVBF
                    WebBrowser1.Document.All("q").SetAttribute("value", "vbforums")
                    WebBrowser1.Document.All("btnI").InvokeMember("Click") 'Click I'm feeling lucky button
                    myState = CurrentState.OnVBF
                Case CurrentState.OnVBF
                    WebBrowser1.Navigate("http://www.reddit.com")
                    myState = CurrentState.AfterVBF
                Case CurrentState.AfterVBF
                    MessageBox.Show("You are now on reddit")
                    myState = CurrentState.Done
    
            End Select
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            myState = CurrentState.BeforeVBF
            WebBrowser1.Navigate("http://www.google.com")
    
        End Sub

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Simple browser login

    Could I not use some kind of wait command until the Busy property is false?

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Not sure how you use that property though.

    My pseudo code is...

    Wait Until Webbrowser1.Busy=False

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width