Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用excel VBA在IE中单击角度(ng单击)搜索按钮_Vba_Excel_Automation_Getelementsbyclassname_Getelementsbyname - Fatal编程技术网

使用excel VBA在IE中单击角度(ng单击)搜索按钮

使用excel VBA在IE中单击角度(ng单击)搜索按钮,vba,excel,automation,getelementsbyclassname,getelementsbyname,Vba,Excel,Automation,Getelementsbyclassname,Getelementsbyname,我是VBA新手。我试图点击“去”搜索按钮后,我登录到一个安全的网站 我尝试了很多方法来点击按钮,但没有成功 这是inspect元素 <button class="button primary pull-right" ng-click="search()" ng-disabled="searchForm.$invalid"> Go <i class="glyphicon glyphicon-chevron-right"></i> </button&

我是VBA新手。我试图点击“去”搜索按钮后,我登录到一个安全的网站

我尝试了很多方法来点击按钮,但没有成功

这是inspect元素

<button class="button primary pull-right" ng-click="search()" ng-disabled="searchForm.$invalid">
    Go <i class="glyphicon glyphicon-chevron-right"></i>
</button>
方法2

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
方法3

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
方法4

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
方法5

     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
方法6

Set ie = CreateObject("InternetExplorer.Application")
ie.document.getElementByClassName("button primary pull-right")(0).Click
任何帮助都将不胜感激


谢谢大家!

我认为您没有给出url,因为它超出了登录范围。这使得解决问题的难度增加了十倍。尽管如此,还是有一些观点

  • ng Click表示其运行角度
  • 有时,在模拟单击事件之前,需要使控件获得焦点
  • 我会使用.querySelector()或.queryselectoral()获取按钮,因为我可以使用Chrome开发工具窗口底部的路径
试试这个代码

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

谢谢你花时间回答我的问题。这里有一个例子。这是来自www.jetblue.com的。如果我想使用VBA点击“查找”按钮。我应该如何修改代码?这是inspect元素。谢谢你花时间调查这件事。我用我的登录和密码登录没有问题。我的问题是,如何在jetblue.com上找到它。“查找”按钮以角度运行。
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