【发布时间】:2019-02-19 07:26:03
【问题描述】:
我正在尝试通过 VBA 单击公司网页上的链接。问题是 HTML 没有名称或 ID。我在这个网站上看到了许多不同的场景,我一直在尝试,但我似乎无法点击这个链接。
我无法共享该站点,因为它是公司 Intranet 站点,但我将共享 HTML 部分,并且我的代码尝试。
这里是 HTML。应该知道,只有将鼠标悬停在菜单上才能访问该链接。
<li title="vendor" class="current"><a class="sf-with-ul" href="javascript:void(0);">Vendor A/P Inquiry<span class="sf-sub-indicator"> »</span></a>
<ul style="width: 7.68em; float: none; display: none; visibility: hidden;">
<li title="Vendor Invoice Inquiry Thru Browser" style="width: 100%; float: left; white-space: normal;"><a style="width: auto; float: none;" href="javascript:top.pageFrame.processSelection('VRJA');">Vendor A/P Inquiry</a></li>
</ul>
</li>
编辑:我将鼠标悬停在父项上以显示我需要的链接是行 <li title="vendor" class="current">
这是我点击此链接的一些尝试(在 HTML 屏幕截图中以蓝色突出显示)
尝试 1:
Dim link As Object
Dim doc As Object
Set doc = ieApp.document
For Each link In doc.Links
Debug.Print link.innerText
If link.innerText = "Vendor A/P Inquiry" Then
link.Click
Exit For
End If
Next link
尝试 2:
Set ieAnchors = ieApp.document.anchors
For Each Anchor In ieAnchors
If Anchor.href = "javascript:top.pageFrame.processSelection('VRJA');" Then
Anchor.Click
Exit For
End If
Next Anchor
尝试 3:
Set buttonclick = ieApp.document.getElementsByTagName("a")
For Each element In buttonclick
If element.href = "javascript:top.pageFrame.processSelection('VRJA');" Then element.Click
Next element
在访问此链接之前,我可以正常浏览网站。
任何帮助都将不胜感激,因为我觉得我在反复尝试相同的解决方案。
【问题讨论】:
标签: html vba excel internet-explorer-11