下面是一个HTML表单及其下方,是一个VB程序,“LoginExamp”,输入用户名和密码。我无法找到该按钮,然后单击它,因为它似乎不显示为mshtml.HTMLInputElement。 “htmlInput.click()”永远不会运行。如何调整loginExamp代码以便点击按钮。谢谢你的帮助。无法找到并单击提交按钮使用mshtml.HTMLInputElement
submit!
随着下面的代码
Public Sub loginExamp()
Dim objIE As SHDocVw.InternetExplorer
Dim htmlDoc As mshtml.HTMLDocument
Dim htmlInput As mshtml.HTMLInputElement
Dim htmlColl As mshtml.IHTMLElementCollection
Dim url As Object
url = "http://localhost/ButtonClickTest.html" 'just a test page with the loginform above
objIE = New SHDocVw.InternetExplorer
With objIE
.Navigate(url)
.Visible = True
While .Busy = True
Threading.Thread.Sleep(2000)
End While
htmlDoc = .Document
htmlColl = htmlDoc.getElementsByTagName("INPUT")
While .Busy = True
Threading.Thread.Sleep(2000)
End While
For Each htmlInput In htmlColl
If htmlInput.name = "Xusername" Then
htmlInput.value = "theusername" 'this works
ElseIf htmlInput.name = "Xpassword" Then
htmlInput.value = "thepassword" 'This works too
End If
If htmlInput.className = "subButton" Then 'This is never true
htmlInput.click() 'This line never runs
End If
Next htmlInput
End With
End Sub
+1
我看到你把你的按钮的类名改为了subButton。起初是不同的;它总是subButton? –
2012-01-31 22:46:30
+0
是的,这是在示例代码中的错误,但不是问题的原因事实上htmlInput.className = =“nothing”在下一个循环中。 –
2012-01-31 22:48:52
+1
而不是使用类和className,你是否尝试过使用名称,就像你对输入元素所做的一样? –
2012-01-31 22:52:34