|
-
Aug 24th, 2010, 11:36 PM
#1
Thread Starter
Member
[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.
-
Aug 25th, 2010, 06:37 AM
#2
Re: Help with clicking login through webBrowser
-
Aug 25th, 2010, 10:54 AM
#3
Thread Starter
Member
Re: Help with clicking login through webBrowser
Thanks for the reply, but im already using whats suggested in that link
Code:
WebBrowser1.Document.GetElementById("login@DEFAULT").InvokeMember("click")
Can someone tell me what the tagName for this button is
HTML Code:
<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>
-
Aug 25th, 2010, 07:05 PM
#4
Re: Help with clicking login through webBrowser
using your html snippet +
vb Code:
WebBrowser1.Document.GetElementById("login@DEFAULT").InvokeMember("click")
it clicked the button as expected. can you post the full html?
 Originally Posted by Datadayne
Can someone tell me what the tagName for this button is
HTML Code:
<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>
the tagName is "input"
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 25th, 2010, 08:35 PM
#5
Thread Starter
Member
Re: Help with clicking login through webBrowser
Thanks for the reply, full html is too long to post, but here is the part of the html that includes the login:
HTML Code:
<form name="TopLoginForm" method="post" action="https://www.locationary.com/web/login/index.jsp?ACTION_TOKEN=tile_loginBar_jsp$JspView$LoginAction" id="m_Login">
<div style="float:right;">
<table border=0>
<tr>
<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>
<tr><td></td><td ></td><td></td><td><a class="Medium " href="http://www.locationary.com/web/login/forgotpwd.jsp">Forgot Password?</a>
</td><td></td></tr>
</table>
</div>
</form>
-
Aug 25th, 2010, 09:09 PM
#6
Re: Help with clicking login through webBrowser
it worked with that too...
put this in a button + click it:
vb Code:
for each element as htmlelement in webbrowser1.document.getelementsbytagname("input")
msgbox(element.getattribute("id"))
next
does the submit button show up?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 25th, 2010, 09:35 PM
#7
Thread Starter
Member
Re: Help with clicking login through webBrowser
Looks like it, Im getting inUserName, inPassName and login@DEFAULT.
Edit:
I tried adding this in the button click rather than in the webBrowser and its working for some odd reason.
Code:
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", "myUser")
ElseIf controlName = "inUserPass" Then
curElement.SetAttribute("Value", "myPass")
End If
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.Document.GetElementById("login@DEFAULT").InvokeMember("click")
End Sub
End Class
Any reasons why its working if I plug it in the button rather than the webBrowser.
Last edited by Datadayne; Aug 25th, 2010 at 09:49 PM.
-
Aug 26th, 2010, 07:58 AM
#8
Re: Help with clicking login through webBrowser
the WebBrowser1_DocumentCompleted event fires more than once when navigating to a page. for an accurate measure of when the page is loaded check webbrowser1.readystate in your WebBrowser1_DocumentCompleted event
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 26th, 2010, 12:27 PM
#9
Thread Starter
Member
Re: Help with clicking login through webBrowser
You mean like this?
vb Code:
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", "user") ElseIf controlName = "inUserPass" Then curElement.SetAttribute("Value", "pass") End If Next If WebBrowserReadyState.Complete Then WebBrowser1.Document.GetElementById("login@DEFAULT").InvokeMember("click") Else : MsgBox("WebBrowser did not complete") End If End Sub
The msgbox doesnt display so it should be completed, I switched wbreadystate.complete with .uninitialized and as expected the msgbox did display.
-
Aug 26th, 2010, 01:19 PM
#10
Re: Help with clicking login through webBrowser
that's how i meant, although you should put the other code inside the 'If WebBrowserReadyState.Complete Then' block too.
i'm guessing it didn't work, or you wouldn't be asking?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 26th, 2010, 01:31 PM
#11
Thread Starter
Member
Re: Help with clicking login through webBrowser
Well switching the id of the login with the value seems to have worked.
vb 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", "user") ElseIf controlName = "inUserPass" Then curElement.SetAttribute("Value", "pass") End If Next theElementCollection = WebBrowser1.Document.GetElementsByTagName("input") For Each curElement As HtmlElement In theElementCollection Dim controlValue As String = curElement.GetAttribute("Value").ToString If controlValue = "Submit" Then curElement.InvokeMember("click") End If Next End Sub
Although I still dont know why using the id doesnt work. Thanks for your time and help .paul.
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
|