怎么用VBS程序点击网页中按钮

怎么用VBS程序点击网页中按钮,第1张

先假设你有一个IE对象,

SET IE=Createobject("Internetexplorer.application")

然后你打开了这个网页,就可以这样了:

With IE.Document

for each i in .GetElementsByClassName("button")

i.click

next

end with

不过你要是给元素分配了唯一的ID就更容易了,这样略麻烦......

某网页按钮内容:

<TD><INPUT TYPE="text" NAME="crystalcount" value="100" size=10 maxlength=10><INPUT type="button" class=btn1_mouseout onmouseover="this.className='btn1_mouseover'" onmouseout="this.className='btn1_mouseout'" value="最大值" onclick="javascript:document.f1.crystalcount.value=3960">你现有500万</TD>

代码:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)

Set vDoc = WebBrowser1.Document

For i = 0 To vDoc.All.length - 1 '检测所有标签

If UCase(vDoc.All(i).tagName) = "INPUT" Then '找到input标签

Set vTag = vDoc.All(i)

If vTag.Type = "button" And vTag.Value = "最大值" Then '找到确定按钮。

vTag.Select '也可以没有这个

vTag.Click '点击提交了,一切都OK了

End If

End If

Next i

End Sub

*但不是对所有网页均有用,有些网页调用其它页面或JS的,就无法使用了。只能用模拟鼠标点击等方法实现了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7841907.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存