我正在尝试自动化 VB.net 中的网页,但我无法在文本框中填写值,我的代码只能单击按钮
网页HTML如下
<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>
我的 VB.net 代码如下:
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