Results 1 to 17 of 17

Thread: [RESOLVED] How to login to website using WebBrowser component?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Resolved [RESOLVED] How to login to website using WebBrowser component?

    I want to make program that will login to phpbb3 forum...

    And I want to use WebBrowser component... but I dont know how to login to forum using it...

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to login to website using WebBrowser component?

    Search these forums, there are loads of examples of people asking the exact same thing.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Well I did some researches here but here is the thing...

    I setup a browser and command button for design... and here is the code:
    Code:
    Private Sub command1_click()
        Dim ie As WebBrowser
        ie.Navigate ("http://forumurl.com/ucp.php?mode=login")
        ie.Document.Forms(0).Elements("username").Value = "stefo"
        ie.Document.Forms(0).Elements("password").Value = "pass"
        ie.Document.Forms(0).submit
        MsgBox "you're in!!!-click OK to close browser"
    End Sub
    I get error: "Object variable or With block variable not set"
    Last edited by stefo911; Jan 19th, 2009 at 04:29 AM.

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to login to website using WebBrowser component?

    You have to wait until your browser has actually loaded the page. Your telling it to navigate to that website and then instantly asking it to enter text into some textboxes that wont even be there yet.
    You should drag an instance of the WebBrowser control onto your form and then place this code (minus the declaring bit obviously as you would already have a webbrowser there now) in the LoadComplete event (or whatever its called).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Like this:

    Code:
    Private Sub command1_click()
        Dim ie As WebBrowser
        ie.Navigate ("http://forumurl.com/ucp.php?mode=login")
    End Sub
    
    private sub WebBrowser1_DocumentCompleted()
        ie.Document.Forms(0).Elements("username").Value = "stefo"
        ie.Document.Forms(0).Elements("password").Value = "pass"
        ie.Document.Forms(0).submit
        MsgBox "you're in!!!-click OK to close browser"
    end sub
    Didn't tried this but I assume it's something like this?

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to login to website using WebBrowser component?

    Yeah very similar to that
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    It doesn't work. It navigates me to the page but it wont log me in.

  8. #8
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to login to website using WebBrowser component?

    Are you sure your text fields on the website are named "username" and "password" ?
    Also, you may need to set the OuterText (or might be InnerText, cant remember) properties instead of the Value
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Well I want to login to the phpBB3 forum so I'm sure fields are username & password.

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to login to website using WebBrowser component?

    This thread could provide valuable hints.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    I tried it,it navigates me to the page but it doesn't log me in...

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to login to website using WebBrowser component?

    Does it raise an error? Perhaps those elements are locate in a different form.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Hey I got it finally...

    I modified code from the page you gave me...

    Code:
    Dim i As Integer
    Sub getMail()
        ie.Navigate ("http://forum.org/ucp.php?mode=login")
        While ie.Busy: DoEvents: Wend
        ie.Visible = True
        While ie.Busy: DoEvents: Wend
        
        'your user id
       ' ie.document.Forms(0).Elements("username").Value = "user"
        'your password
        'ie.document.Forms(0).Elements("password").Value = "pass"
         
         ie.document.All("username").Value = "stefo"
         ie.document.All("password").Value = "nissano19"
         
         
        While ie.Busy: DoEvents: Wend
        
       ' ie.Document.Forms(0).submit
        ie.document.All("Login").Click
    
        While ie.Busy: DoEvents: Wend
        
        MsgBox "you're in!!!-click OK to close browser"
    End Sub
    
    
    
    Private Sub Command1_Click()
    Call getMail
    End Sub

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: How to login to website using WebBrowser component?

    Good to hear that. You may now mark your thread as Resolved by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see it and know that you appreciate their help.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Just one more question... does anybody know how to check if some strings exists on the website that webbrowser component loaded?

    For example,I logged into website through VB but when I do it again it says Object .... With variable block set bla bla... something like that... so I figured why wouldn't I check if page has the word Logout... if it does then app shouldn't login but if it doesn't contains word Logout then it would log the user in...

    And also,how to get content of some field? Cause I want to take content from the field message on forum that I have previously logged in...

    I would like if you would be able to answer me first question,second question isn't that important to me....

  16. #16
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to login to website using WebBrowser component?

    You can get the entire HTML source of the website your browser is displaying by using the DocumentText property so you might be able to just use IndexOf or a RegEx query to see if the word Logout exists in that string.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  17. #17

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    12

    Re: How to login to website using WebBrowser component?

    Okay,thanks will give it a shot.

Posting Permissions

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



Click Here to Expand Forum to Full Width