Results 1 to 11 of 11

Thread: [RESOLVED]Help with clicking login through webBrowser

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    57

    [RESOLVED]Help with clicking login through webBrowser

    Here is the source
    HTML Code:
    <td rowspan=2> </td><td><img src="http://www.locationary.com/web/img/LocationaryImgs/icons/txt_email.gif"></td> 
    <td><input class="Data_Entry_Field_Login" type="text" name="inUserName" id="inUserName"  size="25"></td> 
    <td><img src="http://www.locationary.com/web/img/LocationaryImgs/icons/txt_password.gif"></td> 
    <td><input  class="Data_Entry_Field_Login"  type="password" name="inUserPass" id="inUserPass"></td> 
    <td style="padding-top:2"><input id="login@DEFAULT" type="image" src="http://www.locationary.com/web/img/LocationaryImgs/btn/white/btn_login_40x20_fff_normal.gif" onmouseover="javascript:this.src='http://www.locationary.com/web/img/LocationaryImgs/btn/white/btn_login_40x20_fff_highlighted.gif'" onmouseout="javascript:this.src='http://www.locationary.com/web/img/LocationaryImgs/btn/white/btn_login_40x20_fff_normal.gif'" value="Submit" alt="Login" ></td></tr>
    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' Part 1: Use WebBrowser control to load web page
            WebBrowser1.Navigate("http://www.locationary.com")
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            ' Part 2: Username and password
            Dim theElementCollection As HtmlElementCollection
            theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
            For Each curElement As HtmlElement In theElementCollection
                Dim controlName As String = curElement.GetAttribute("name").ToString
                If controlName = "inUserName" Then
                    curElement.SetAttribute("Value", "myUsername")
                ElseIf controlName = "inUserPass" Then
                    curElement.SetAttribute("Value", "myPassword")
                End If
            Next
            WebBrowser1.Document.GetElementById("login@DEFAULT").InvokeMember("click")
        End Sub
    End Class
    Everything works fine except the login, it gives me an "Object reference not set to an instance of an object" error.
    Last edited by Datadayne; Aug 26th, 2010 at 01:32 PM.

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