|
-
Jan 3rd, 2010, 07:47 PM
#1
Thread Starter
Lively Member
[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.
-
Jan 3rd, 2010, 08:03 PM
#2
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:
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:
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("value").ToString
If controlName = "Log In" Then
curElement.InvokeMember("Click")
End If
Next
that should work. i looked at the source of that page and they have:
<input type="submit" value=" Log In ">
so you might need to change "Log In" to " Log In " in the code
Last edited by stateofidleness; Jan 3rd, 2010 at 08:11 PM.
-
Jan 3rd, 2010, 08:16 PM
#3
Thread Starter
Lively Member
Re: Click button on webbrowser(autologin)
 Originally Posted by stateofidleness
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:
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:
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input") For Each curElement As HtmlElement In theElementCollection Dim controlName As String = curElement.GetAttribute("value").ToString If controlName = "Log In" Then curElement.InvokeMember("Click") End If Next
that should work. i looked at the source of that page and they have:
<input type="submit" value=" Log In ">
so you might need to change "Log In" to " Log In " 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
-
Jan 3rd, 2010, 08:22 PM
#4
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 " Log In " (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
-
Jan 3rd, 2010, 08:28 PM
#5
New Member
Re: Click button on webbrowser(autologin)
use this
VB.Net Code:
WebBrowser1.Document.Forms(1).InvokeMember("submit")
-
Jan 3rd, 2010, 08:34 PM
#6
Thread Starter
Lively Member
Re: Click button on webbrowser(autologin)
 Originally Posted by NosFtw
use this
VB.Net Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|