1

我对 VBA 并不陌生,但我对任何与 Web 交互的东西都不熟悉。我可以打开有几个图标的网页。我需要有关单击特定图标的帮助。这是我右键单击所需图标并单击“检查元素”时出现的 HTML:

<div title="" class="myapps-myapp resource" position="N" index="22">
    <div class="myapps-icon-background"></div>
    <a class="myapps-icon" href="#">
    <img class="iconImage" alt="SomeName"
        src="Resources/Icon/aklhdjQ2QWJGVVQxcHpUcEJ5RG5FcEZwcytzPQ--
?size=48"
        iconid="akltdjStWJGVVRxcHpUcEJ7QG3FcEZwtytzMT">
    </a>
    <div class="myapps-status"></div>
    <div class="myapps-name">SomeName</div>
    </div>

这是我到目前为止的 VBA 代码:

Sub test()
Dim oHTML_Element As IHTMLElement
Dim oBrowser As Internet Explorer
Dim objIE As Variant
Set objIE = Create Object("InternetExplorer.Application")
objIE.navigate "http://The webpage goes here" 'This open the site       
While objIE.readyState <> READYSTATE_COMPLETE And objIE.readyState & _
    <> READYSTATE_LOADED
    DoEvents
Wend
For Each oHTML_Element In objIE.document.getElementsByName & _
("SomeName")
    oHTML_Element.Click   'This does not work!
Next
End Sub

任何帮助将不胜感激。谢谢!

4

1 回答 1

0

它是alt您要匹配的属性的值。没有循环。

objIe.document.querySelector("[alt='RevenueCycle P0657 YAVA_AZ']").click

虽然它实际上可能是a您要点击的标签

objIe.document.querySelector("[index='22'] .myapps-icon").click

阅读:

  1. CSS 选择器
  2. 查询选择器
于 2019-10-13T05:54:48.293 回答