CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Location
    .NET3.5 / VS 2008
    Posts
    2

    Help clicking login button on a webpage

    I am having trouble getting my form to click the login button on a website. I can get my username and password to load into the sites text boxes but I auto click the button . I have been trying different code for weeks and I have let that button whoop-me. Please Help. This is my main form and my code as of now.

    >Private Sub lblPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
    Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
    login1.ShowDialog()
    End Sub
    Private Sub txtUser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub
    Private Sub SwaggerLee1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    WebBrowser1.Navigate(ComboBox1.Text)
    System.Threading.Thread.Sleep(4000) ' Delay 4 seconds to render login

    End Sub
    Private Sub lblUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblUser.Click
    End Sub
    Private username, password As String

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    Login(username, password)
    End Sub

    Private Sub Login(ByVal username As String, ByVal password As String)

    Dim theWElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")

    For Each curElement As HtmlElement In theWElementCollection
    Dim controlName As String = curElement.GetAttribute("id").ToString
    If controlName = "emailAddressLocal" Then
    curElement.SetAttribute("Value", lblUser.Text)
    ElseIf controlName = "pswdLocal" Then
    curElement.SetAttribute("Value", lblPass.Text)
    End If
    Next
    End Sub<

    The Get Elements By Id Method I've been using to click the Button doesn't work at all, Please Help.

    Here is the Source Code for that Button.

    <form name="frmLogIn-tbar" id="signInBoxLocal" method="post" action="/?cmd=sb- login&from=/?cmd=home">


    <label class="loginLabel">Email Address or Swag Name:</label>
    <input class="secBorder" title="Enter your email address" type="text" name="emailAddress" id="emailAddressLocal" onKeyPress="return enterLoginTBLocal(event);" tabindex="1"/>
    <a href="#" onClick="sendEmailTBLocal(); return false" class="emailPass highlight1">Forgot Password?</a>
    <label class="loginLabel">Password:</label>
    <input class="secBorder" title="Enter your password" type="password" name="pswd" id="pswdLocal" onKeyPress="return enterLoginTBLocal(event);" tabindex="2"/>

    <div class="btn1 btnLogin" onclick="logInTBLocal();">Login</div>
    <div class="persist">
    <input class="persist" type="checkbox" name="persist" id="persistLocal" checked onKeyPress="return enterLoginTBLocal(event);" onchange="prettyCheckbox('persist',this)" tabindex="3"/>
    <label class="persist" for="persistLocal" class="persistLabel">Remember Me</label>
    <div class="clear"></div>


    Please Help!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help clicking login button on a webpage

    Find the button, and call .Submit
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2010
    Location
    .NET3.5 / VS 2008
    Posts
    2

    Re: Help clicking login button on a webpage

    I've Been over the entire Source Code for this webpage. There is no "Id" or "Name" for the Login Button in the source code. Here is the only reference to It that I could find.

    <div class="btn1 btnLogin" onclick="logInTBLocal();">Login</div>

    Any Suggestions?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Help clicking login button on a webpage

    Can't help automating login, sorry. See the AUP at the bottom of every page here
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured