我正在尝试以编程方式单击按钮。该按钮位于网站的第 3 页。它没有任何 id 。它只有名称、类型和值。该按钮的 HTML 代码如下所示
<FORM NAME='form1' METHOD='post' action='/dflogin.php'>
<INPUT TYPE='hidden' NAME='txtId' value='E712050-15'>
<INPUT TYPE='hidden'NAME='txtassId' value='1'>
<INPUT TYPE='hidden' NAME='txtPsw' value='HH29'>
<INPUT TYPE='hidden' NAME='txtLog' value='0'>
<h6 align='right'>
<INPUT TYPE='SUBMIT' NAME='btnSub' value='Next' style='background-color:#009900; color:#fff;'></h6></FORM>
我已经在 vb.net 2008 速成版中尝试过这些代码...
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("value") = "Next" Then
webpageelement.InvokeMember("click")
End If
Next
还有第二个
theElementCollection = WebBrowser1.Document.GetElementsByTagName("INPUT")
For Each curElement As HtmlElement In theElementCollection
ctrlIdentity = curElement.GetAttribute("innerText").ToString
If ctrlIdentity = "Next" Then
curElement.InvokeMember("click")
End If
Next
第三个是
Dim l_forms = WebBrowser1.Document.GetElementsByTagName("form")
If l_forms.Count > 0 Then
l_forms.Item(0).InvokeMember("submit")
End If
and 4th one is
Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml,"NAME='btnSub'", "NAME='btnSub' id='btnSub'") 'insert id into youre button
WebBrowser1.Document.GetElementById("btnSub").InvokeMember("click") 'click on btnSub
最后一个是
Dim i As Integer
Dim allButtons As HtmlElementCollection
allButtons = WebBrowser1.Document.GetElementsByTagName("input")
i = 0
For Each webpageelement As HtmlElement In allButtons
i += 1
If i = 5 Then
webpageelement.InvokeMember("click")
End If
Next
这些所有代码都无法单击该按钮。请为单击此按钮提出适当的解决方案。太感谢了