1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > html input提交按钮无法使用 无法找到并单击提交按钮使用mshtml.HTMLInputElement

html input提交按钮无法使用 无法找到并单击提交按钮使用mshtml.HTMLInputElement

时间:2023-06-06 05:38:25

相关推荐

html input提交按钮无法使用 无法找到并单击提交按钮使用mshtml.HTMLInputElement

下面是一个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? –

-01-31 22:46:30

+0

是的,这是在示例代码中的错误,但不是问题的原因事实上htmlInput.className = =“nothing”在下一个循环中。 –

-01-31 22:48:52

+1

而不是使用类和className,你是否尝试过使用名称,就像你对输入元素所做的一样? –

-01-31 22:52:34

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。