Results 1 to 6 of 6

Thread: [RESOLVED] Click button on webbrowser(autologin)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    83

    Resolved [RESOLVED] Click button on webbrowser(autologin)

    Hi,


    I've managed to fill in the username and password with the necessary details but I can't seem to click the submit button.

    This method works on all other sites I've tried, but not this one. The button name is submit (Tryed all from source and looped through the input elements which it can't be found on there).

    Might it be on another form or is it somthing to do with JS?

    https://www.

    Thanks

    code I used:

    Code:
    webbrowser1.document.getelementbyid("name").invokemember("click")
    and other methods to click the button, but nothing.

    p.s i'm sure the button is called submit?
    Last edited by meight; Jan 3rd, 2010 at 09:09 PM.

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

    Re: Click button on webbrowser(autologin)

    i'm not sure how to do it when there is no ID given, but something like this would be done after you know you have the correct button:

    vb.net Code:
    1. Me.Webbrowser1.document.forms(0).InvokeMember("Click")

    im not 100% on the syntax, but basically, since it doesn't have an ID, you'll have to iterate through the pages forms and find the right one, then invoke a click event on that button

    EDIT

    vb.net Code:
    1. Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
    2.         For Each curElement As HtmlElement In theElementCollection
    3.             Dim controlName As String = curElement.GetAttribute("value").ToString
    4.             If controlName = "Log In" Then
    5.                 curElement.InvokeMember("Click")
    6.             End If
    7.         Next

    that should work. i looked at the source of that page and they have:
    <input type="submit" value="&nbsp;Log In&nbsp;">

    so you might need to change "Log In" to "&nbsp;Log In&nbsp;" in the code

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    83

    Re: Click button on webbrowser(autologin)

    Quote Originally Posted by stateofidleness View Post
    i'm not sure how to do it when there is no ID given, but something like this would be done after you know you have the correct button:

    vb.net Code:
    1. Me.Webbrowser1.document.forms(0).InvokeMember("Click")

    im not 100&#37; on the syntax, but basically, since it doesn't have an ID, you'll have to iterate through the pages forms and find the right one, then invoke a click event on that button

    EDIT

    vb.net Code:
    1. Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
    2.         For Each curElement As HtmlElement In theElementCollection
    3.             Dim controlName As String = curElement.GetAttribute("value").ToString
    4.             If controlName = "Log In" Then
    5.                 curElement.InvokeMember("Click")
    6.             End If
    7.         Next

    that should work. i looked at the source of that page and they have:
    <input type="submit" value="&nbsp;Log In&nbsp;">

    so you might need to change "Log In" to "&nbsp;Log In&nbsp;" in the code
    Top one dont work, also there are two buttons, the bottom one also doesn't work.

    ps I think I can click the button in vb6, not using the webbrowser control tho, so got to be possable, thanks

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

    Re: Click button on webbrowser(autologin)

    just to clarify, you ARE using a webbrowsercontrol correct?

    the problem with that page is the login button does not have a "name" or an "ID", so you are going to have to loop through the elements of type "input" and compare the values with an If statement. If the value is equal to "Log In" or "&nbsp;Log In&nbsp; " (as it's coded in the HTML source, then Invoke your click event.

    that bottom code should work. try stepping through the code with F5 to see what the values curElement is returning. This will tell you the value of the Log in button

  5. #5
    New Member
    Join Date
    Dec 2009
    Posts
    15

    Re: Click button on webbrowser(autologin)

    use this

    VB.Net Code:
    1. WebBrowser1.Document.Forms(1).InvokeMember("submit")

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    83

    Re: Click button on webbrowser(autologin)

    Quote Originally Posted by NosFtw View Post
    use this

    VB.Net Code:
    1. WebBrowser1.Document.Forms(1).InvokeMember("submit")
    Ahah, I never thought of putting the control name in there, nice, + 1.

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