Results 1 to 20 of 20

Thread: Click Forum Login Button

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Question Click Forum Login Button

    Hi!

    I'm trying to make a program that will automatically log me into a forum. I have the webbrowser control and a button. the site is automatically loaded on form load. I want it to log me in using my username and password when i click the button. I tried it on yahoo.com to test and worked fine. But for some reason when I try it with my forum it doesn't work. My forum is SMF. It seems that the problem lies with the Login button itself. I can easily send the username and password to the corresponding boxes but when it comes to clicking the Login button it fails. What makes that Login button different from the Login button of Yahoo other than having a different name? Below is an example of the code I was using. How can I get it to successfully click the SMF Login button? Please post example code if possible.

    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            WebBrowser1.Document.GetElementById("vb_login_username").SetAttribute("value", TextBox1.Text)
            WebBrowser1.Document.GetElementById("vb_login_password").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("Login").InvokeMember("click")
        End Sub
    Best,

    ~Chris

  2. #2
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Click Forum Login Button

    what's the HTML code for the button? also, have you made sure that the actual textboxes are getting populated fully before "clicking" the button? might need to put the "clicking" line in a timer and check to see if the textboxes contain a value before issuing the "click"

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    I know everything works fine because I tried having it fill the text boxes and not click the login button and it filled them correctly. Then I add the Login code after that. On a site like yahoo it works fine. Click the button and it sends the correct info to the text boxes of the yahoo page and clicks the login button and I'm logged in. Works perfect.

    I use the GetElementById method to fill the boxes based on their Id in the html code. (re: code I posted above) I use the same thing for the Login button and InvokeMember("click") to make it click the button. All the Id names are correct. Why is it not working? I heard somewhere it has to do with how smf processes the login or something. Does anybody know how this works? Please explain.

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Click Forum Login Button

    ...or don't post the source code... stop comparing it to yahoo.. it isn't yahoo.
    i had to go find another smf-based forum (see previous post's first request) and nowhere in it did I find an HTML element with the ID "Login" so... that's probably your problem.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    Here is the Login code on the Login Page:

    Code:
    <div class="roundframe">
    				<dl>
    					<dt>Username:</dt>
    
    					<dd><input type="text" name="user" size="20" value="" class="input_text" /></dd>
    					<dt>Password:</dt>
    					<dd><input type="password" name="passwrd" value="" size="20" class="input_password" /></dd>
    				</dl>
    				<dl>
    					<dt>Minutes to stay logged in:</dt>
    					<dd><input type="text" name="cookielength" size="4" maxlength="4" value="60" class="input_text" /></dd>
    					<dt>Always stay logged in:</dt>
    
    					<dd><input type="checkbox" name="cookieneverexp" class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>
    				</dl>
    				<p><input type="submit" value="Login" class="button_submit" /></p>
    				<p class="smalltext"><a href="http://mydomain.com/index.php?action=reminder">Forgot your password?</a></p>
    				<input type="hidden" name="hash_passwrd" value="" />
    			</div>
    This is from an smf forum. It uses "Login" as the Id. See:

    Code:
    <p><input type="submit" value="Login" class="button_submit" /></p>
    So wrong Id is not my problem. I used all the Ids mentioned in the above code.

  6. #6
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Click Forum Login Button

    then you need an HTML lesson..

    <p><input type="submit" value="Login" class="button_submit" /></p>

    i don't see the word "id" in that line ANYWHERE
    you're going to have to loop through the HTMLCollection of "input" elements and check the attribute "value" to see if it equals "Login", if it does, invoke the click method.

    for kicks, here's the code for the yahoo login page:

    HTML Code:
    <div id='inputs'> 
    <label for='username'>Yahoo! ID</label> 
    <input name='login' id='username' maxlength='96' tabindex='1'> 
    <p id='ex'>(e.g. [email protected])</p> 
     
    <label for='passwd'>Password</label> 
    <input name='passwd' id='passwd' type='password' maxlength='64' tabindex='2'> 
    </div>
    notice anything? the username and password input fields have ID's (username and 'passwd', respectively.

    try this:

    vb.net Code:
    1. Dim webBrowserDocument As HtmlDocument = webBrowser.Document
    2. Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    3. For Each element As HtmlElement In hec
    4.   If element.GetAttribute("name") = "Login" Then
    5.           'Invoke here
    6.   End If
    7. Next

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    Ok this is starting to make sense. For the sake of simplifying things I created 2 buttons. Button1 sends the username and password to the corresponding boxes in the forum. Button2 clicks the Login button.

    Button1 code:

    Code:
    Me.WebBrowser1.Document.GetElementById("user").SetAttribute("value", "myusername")
            Me.WebBrowser1.Document.GetElementById("passwrd").SetAttribute("value", "mypassword")
    Button2 code:

    Code:
    Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
            Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    
            For Each element As HtmlElement In hec
                If element.GetAttribute("name") = "Login" Then
                    'InvokeMember Here???????????????
                End If
            Next
    I'm new to VB. So, I'm a bit confused on how to use the InvokeMember in this case. It was easy in my first example with the yahoo page. But this is a little different. How would I type it out?

  8. #8

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    It didn't work. I click the button and it does nothing. Code below:

    Code:
    Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
            Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    
            For Each element As HtmlElement In hec
                If element.GetAttribute("name") = "Login" Then
                    element.InvokeMember("click")
                End If
            Next

  10. #10

  11. #11
    Addicted Member
    Join Date
    Jul 2010
    Posts
    134

    Re: Click Forum Login Button

    OT
    can you give source code to log in on yahoo..mesenger

  12. #12

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    Website is udgclan.com. But this will be the same exact for all sites using smf 2.0RC3 for their forum.

  14. #14
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: Click Forum Login Button

    Why not just do

    Code:
    WebBrowser1.document.forms(0).invokemember("submit")
    If I helped you out, please take the time to rate me

  15. #15

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    It still isn't working. I apologize if I'm a bit retarded at times. I really am new at this and I'm trying to grasp what I'm doing. Did I insert the code into the right spot? Code below:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
            Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    
            For Each element As HtmlElement In hec
                If element.GetAttribute("name") = "Login" Then
                    WebBrowser1.Document.Forms(0).InvokeMember("button_submit")
                End If
    
            Next
    
        End Sub

  16. #16
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Click Forum Login Button

    Well, you're combining the two suggestions, which really doesn't work in this case:

    either do:

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
    4.         Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    5.  
    6.         For Each element As HtmlElement In hec
    7.             If element.GetAttribute("name") = "Login" Then
    8.                 element.InvokeMember("click")
    9.             End If
    10.  
    11.         Next
    12.  
    13.     End Sub

    or the other suggestion (which is a good suggestion):
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.      WebBrowser1.Document.Forms(0).InvokeMember("submit") 'not button_submit
    3. End Sub

  17. #17

    Thread Starter
    New Member
    Join Date
    Oct 2010
    Posts
    8

    Re: Click Forum Login Button

    It finally worked!!! Thank you so much!!!

    The first option didn't work. It was the second option that worked for me. The below code successfully clicks the login button on an smf forum.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            WebBrowser1.Document.Forms(0).InvokeMember("submit") 'not button_submit
    
        End Sub

  18. #18
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Click Forum Login Button

    Good deal. Sometimes the Forms way (the way that worked) can be troublesome, like if you wanted to add a Poll or a contact form to the main page, it might re-order the form's place in the HTML document.

  19. #19
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    Re: Click Forum Login Button

    Yes, but if that was the case you would take another route to do it.

    Something like:

    Code:
            Dim htmEle As HtmlElement = (From elem In WebBrowser1.Document.GetElementsByTagName("input") Where elem.OuterHtml.ToLower.Contains("class=button_submit") Select elem)(0)
            htmEle.InvokeMember("click")
    If I helped you out, please take the time to rate me

  20. #20
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Click Forum Login Button

    look at the code here " If element.GetAttribute("name") = "Login" Then"
    now look closer here "GetAttribute("name")" was there a "name" in the button call " Login"? no that should be "value"

    Quote Originally Posted by DeepMagic22 View Post
    It still isn't working. I apologize if I'm a bit retarded at times. I really am new at this and I'm trying to grasp what I'm doing. Did I insert the code into the right spot? Code below:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
            Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    
            For Each element As HtmlElement In hec
                If element.GetAttribute("name") = "Login" Then
                    WebBrowser1.Document.Forms(0).InvokeMember("button_submit")
                End If
    
            Next
    
        End Sub
    Should look like this
    Code:
    Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
            Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
    
            For Each element As HtmlElement In hec
                If element.GetAttribute("value") = "Login" Then
                    element.InvokeMember("click")
                End If
            Next
    Last edited by newprogram; Nov 1st, 2010 at 08:19 PM.
    Live life to the fullest!!

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