【发布时间】:2018-08-18 14:20:18
【问题描述】:
我是 VBA 新手。登录到安全网站后,我试图单击“GO”搜索按钮。
我尝试了很多方法来点击按钮,但都没有成功。
这里是检查元素。
<button class="button primary pull-right" ng-click="search()" ng-disabled="searchForm.$invalid">
Go <i class="glyphicon glyphicon-chevron-right"></i>
</button>
这是我尝试过的。
方法一
Set HTMLDoc = HTMLDoc.class("button primary pull-right").document
Set button = HTMLDoc.getElementsByTagName("BUTTON")(0) 'first button
button.Click
For i = 1 To 5
button.Click
DoEvents
Next
方法二
For Each hyper_link In allhyperlinks
If hyper_link.class = "button primary pull-right" Then
hyper_link.Click
Exit For
End If
Next hyper_link
方法三
Set allhyperlinks = IE.document.getElementsByTagName("button")
For Each hyper_link In allhyperlinks
If hyper_link.getAttribute("class") = "search" Then
hyper_link.Click
Exit For
End If
Next
方法四
Dim oHTML_Element As IHTMLElement
Dim oBrowser As InternetExplorer
Dim ie As Variant
For Each oHTML_Element In ie.document.getElementsByName("button")
If oHTML_Element.className = "button primary pull-right" Then
oHTML_Element.Click
End If
Next
方法五
Set ie = CreateObject("InternetExplorer.Application")
With ie
Do Until .readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:15"))
ie.document.getElementsByClassName("button primary pull-right").Click
Application.Wait (Now + TimeValue("0:00:1"))
End With
方法六
Set ie = CreateObject("InternetExplorer.Application")
ie.document.getElementByClassName("button primary pull-right")(0).Click
任何帮助将不胜感激。
谢谢!
【问题讨论】:
标签: vba excel automation getelementsbyclassname getelementsbyname