Reputation: 1
I am trying to automate a webpage in VB.net but I am unable fill values in text box my code only clicking on button
Webpage HTML as follows
<TD align=left height="25" width="350">
<input type="text" name="UserName" size="20">
</TD>
<TD align=left height="25" width="350">
<input type="password" name="Password1" size="20" maxlength="12">
</TD>
<TD align=left height="25" width="350">
<input type="button" onClick="UserVer();" value="Submit"name="BLogin">
</TD>
My VB.net code is follows:
Dim doc As HtmlDocument = wc.Document
Dim link As HtmlElement
Dim links As HtmlElementCollection = wc.Document.All
Dim dom = doc.GetElementsByTagName("a")
Dim t As HtmlElement = wc.Document.All(Name)
For Each link In links
If link.GetAttribute("name") = "UserName" Then
link.SetAttribute("value", UNameTxt.Text)
End If
Next
For Each link In links
If link.GetAttribute("name") = "Password1" Then
link.SetAttribute("value", UPassTxt.Text)
End If
Next
For Each link In links
If link.GetAttribute("value") = "Submit" Then
link.InvokeMember("click")
Exit Sub
End If
Next
Upvotes: 0
Views: 324
Reputation: 34846
Since you have no control over the source you are trying to automate, then I suggest a library such as WatiN to assist in selecting the items you wish to work, like this:
Here is an example of going to Google and doing a search using WatiN
:
' Go to URL for Google search
Dim browser As New IE("http://www.google.com/")
' Find the search text box by name and type text `WatiN` in the box
browser.TextField(Find.ByName("q")).TypeText("WatiN")
' Find the search button by name and click the button
browser.Button(Find.ByName("btnG")).Click()
You can find elements by name, style, ID, etc. and then perform actions on the elements.
Upvotes: 2