J. Scott Elblein
Well-known member
Hello
New to VB.net. I have a form that i need to fill a login and pass, and then click the submit button on the form.
I already have the filling out of the form figured out, however I need some help on clicking the button.
The problem is, that depending which page I use, and sometimes even randomly, the name/id change slightly, so I can't really hardcode a single name or id to try and find the button in order to click it. For example: the string for the id and name always contain the word "loginbutton". Sometimes it's only that, but more often than not, it'll be something like "id="ctl00_Main_SplashDisplay_login_loginbutton".
So I need to somehow search through the id's for the text "loginbutton" in the string so that I can get the entire string, to use for the click event.
I am not sure how to do this. Is there a specific propertie I can simply look at in webbrowser1.document?
Here is the current code I am using that needs adjustment:
I have even tried using a regular expression (I'm probably using it wrong) such as this:
But that comes up empty.
I have a strong feeling this is really simple, but my unfamiliarity with vb.net is hampering my progress. Any help is greatly appreciated.
P.S. I am using VS2005 and .NET 2.0 (VB.NET)
New to VB.net. I have a form that i need to fill a login and pass, and then click the submit button on the form.
I already have the filling out of the form figured out, however I need some help on clicking the button.
The problem is, that depending which page I use, and sometimes even randomly, the name/id change slightly, so I can't really hardcode a single name or id to try and find the button in order to click it. For example: the string for the id and name always contain the word "loginbutton". Sometimes it's only that, but more often than not, it'll be something like "id="ctl00_Main_SplashDisplay_login_loginbutton".
So I need to somehow search through the id's for the text "loginbutton" in the string so that I can get the entire string, to use for the click event.
I am not sure how to do this. Is there a specific propertie I can simply look at in webbrowser1.document?
Here is the current code I am using that needs adjustment:
VB.NET:
Private Function ClickSubmitButton()
Dim theElementCollection As HtmlElementCollection = wbrMyspace.Document.GetElementsByTagName("loginbutton")
Try
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("loginbutton") Then
' Javascript has a click method and this is what we want to do,
' we want to invoke the click method on the current submit button element.
curElement.InvokeMember("click")
Exit For
End If
Next
Return True
Catch ex As Exception
Return False
End Try
End Function
VB.NET:
Private Function ClickSubmitButton()
Dim regex As Regex = New Regex("\w*loginbutton", RegexOptions.IgnoreCase Or RegexOptions.CultureInvariant Or RegexOptions.IgnorePatternWhitespace Or RegexOptions.Compiled)
Dim theElementCollection As HtmlElementCollection = wbrMyspace.Document.GetElementsByTagName(regex.ToString)
Try
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals(regex.ToString) Then
' Javascript has a click method and this is what we want to do,
' we want to invoke the click method on the current submit button element.
curElement.InvokeMember("click")
Exit For
End If
Next
Return True
Catch ex As Exception
Return False
End Try
End Function
I have a strong feeling this is really simple, but my unfamiliarity with vb.net is hampering my progress. Any help is greatly appreciated.
P.S. I am using VS2005 and .NET 2.0 (VB.NET)