对于版本4.2.1,VBA不会点击<a> within </a> <li> <a>

时间:2017-10-03 11:56:54

标签: html vba

I am navigating to a webpage with an unordered list. Now I have to click an 'anchor' tag within a specific 'li' tag.

The part of the source code is,

<UL class="x-tab-strip x-tab-strip-top" id=ext-gen151>
  <LI id=infoPageinfoPanelID__infoPage_myTab_pubst_pubstructStructureGWT _nodup="30817">
    <A class=x-tab-strip-close></A>
    <A class=x-tab-right href="#">
      <EM class=x-tab-left>
<SPAN class=x-tab-strip-inner>
<SPAN class="x-tab-strip-text ">Structure</SPAN>
</SPAN>
</EM>
    </A>
  </LI>
</UL>

The anchor tag does not have a name or ID and has a class name(" x-tab-right ").

I tried the following vba code for simulating a click on that tag,

Dim targetSpan As HTMLObjectElement
Set targetSpan = doc.getElementById("infoPageinfoPanelID__infoPage_myTab_pubst_pubstructStructureGWT").getElementsByTagName("a")(1)
targetSpan.click

=> Code :

Dim AllSpanElements As IHTMLElementCollection
Dim spanCounter As Long
Set AllSpanElements = doc.getElementsByTagName("li")
For spanCounter = 0 To AllSpanElements.Length - 1
With AllSpanElements(spanCounter)
    If (.innerText) = "Structure" Then
                .ParentElement. ParentElement.ParentElement.Click
        Exit For
    End If
End With
Next

I got the 2nd code from StackOverflow.

Both the code doesn't do anything. What am I doing wrong?

Thanks in advance.

0 个答案:

没有答案