【问题标题】:Clicking an Angular (ng-click) search button in IE using excel VBA使用 excel VBA 在 IE 中单击 Angular(ng-click)搜索按钮
【发布时间】: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


    【解决方案1】:

    我认为您没有提供 url,因为它超出了登录范围。这使得解决问题变得困难十倍。不过还是有几点。

    【讨论】:

    • 感谢您花时间回答我的问题。这是一个例子。这是来自 www.jetblue.com。如果我想使用 VBA 点击“查找”按钮。我应该如何修改代码?这是检查元素。
    【解决方案2】:

    试试这个代码

    Sub Test()
    Dim ie          As Object
    Dim e           As Object
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    With ie
        .Visible = True
        .navigate "www.jetblue.com"
        Do Until .readyState = 4: DoEvents: Loop
    
        For Each e In .document.getElementsByTagName("input")
            If e.ID = "email_field" Then
                e.Value = "your email"
            ElseIf e.ID = "password_field" Then
                e.Value = "your password"
            End If
        Next e
    
        For Each e In .document.getElementsByTagName("input")
            If e.ID = "signin_btn" And e.Type = "submit" Then e.Click: Exit For
        Next e
    End With
    End Sub
    

    【讨论】:

    • 感谢您花时间研究此问题。我用我的登录名和密码登录没有问题。我的问题是,如何在 jetblue.com 上点击“查找”。 “查找”按钮正在运行 Angular。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多