Excel VBA来选择网页上的导航选项卡



被困在网页的某个区域,似乎不知道如何选择任何一个导航选项卡。我已经完成了ID、密码和其他几个屏幕的编码,可以进入这个屏幕。尝试了几乎所有的";GetElementBy";这是存在的(我认为(,但没有用。据我所知,标签并没有在自己的框架中。这是选项卡的HTML代码。如果有人能帮忙快速挑选一个,我们将不胜感激。

<ul class="nav nav-tabs">
<li ng-class="{active:isSet(1)}" class="active">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(1)">
Prototypes
</a>
</li>
<li ng-class="{active:isSet(2) || isSet(3)}">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(2);">
Devices
</a>
</li>
<li ng-class="{active:isSet(4)}" ng-show="!IsInitialRelease">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(4)">
Notices
</a>
</li>
<li ng-class="{active:isSet(9)}" ng-show="!IsInitialRelease">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(9)">
Assembly Details
</a>
</li>
<li ng-class="{active:isSet(7)}" ng-show="!IsInitialRelease">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(7)">
Waivers
</a>
</li>
<li ng-class="{active:isSet(8)}" ng-show="!IsInitialRelease">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(8)">
Notifications
</a>
</li>
<li ng-class="{active:isSet(5)}" ng-show="!IsInitialRelease">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(5)">
Permits
</a>
</li>
<li ng-class="{active:isSet(6)}">
<a href="" role="tab" data-toggle="tab" ng-click="setTab(6)">
&nbsp;Search&nbsp;
</a>
</li>
</ul>

从源代码来看,它看起来像是一个Angular站点,您正试图使用IE VBA Automation进行自动化。

我们可以从源代码中注意到两件事。

  1. 活动选项卡为li标记设置了class="active"属性
  2. 每个li标记都包含一个带有Angular click(ng-click(事件的超链接

在这种情况下,

  1. 我们可以首先尝试循环使用li标记并删除class="active"属性
  2. 通过匹配超链接文本找到所需的选项卡,然后单击该超链接,然后为该选项卡设置class="active"属性

这些步骤可以帮助您选择所需的选项卡。

样本代码:

Sub demo()
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://Your_Web_page_address_here..."
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set elems = ie.document.getElementsByTagName("li")

For Each elem In elems
'  Debug.Print (elem.getAttribute("class"))
If (elem.getAttribute("class")) = "active" Then

elem.removeAttribute ("class")

Exit For
End If
Next elem

For Each elem In elems
'  Debug.Print (elem.innerText)
If (elem.innerText) Like "*Devices*" Then
elem.Children(0).Click
elem.setAttribute "class", "active"
Exit For
End If
Next elem

'ie.Quit
End Sub

您可以尝试调试示例代码,以了解它是如何一步一步地工作的,此外,您还可以尝试根据您的需求对其进行修改。