Ниже приведена HTML-форма, а ниже - процедура vb «LoginExamp», которая вводится в имя пользователя и пароль. Однако я не могу найти кнопку и щелкнуть ее, поскольку она не отображается как mshtml.HTMLInputElement. "htmlInput.click ()" никогда не запускается. Как я могу настроить код loginExamp, чтобы кнопка была нажата. Спасибо за любую помощь.
<form id="loginform" name="loginform" method="post" action="">
<input id="username" class="formfield" type="text" value="User Name" maxlength="40" name="Xusername">
<input id="password" class="formfield" type="password" onfocus="clearDefault(this)" maxlength="40" name="Xpassword">
<button class="subButton" onclick="javascript: submitform()">submit!</button>
</form>
С кодом ниже
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