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? –

2012-01-31 22:46:30

+0

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

2012-01-31 22:48:52

+1

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

2012-01-31 22:52:34

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值