VBA / Excel:单击列表 (<li>) 中的链接 (<a>)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22955946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA / Excel: click link (<a>) within list (<li>)
提问by user2571510
I am pretty new to VBA and hope someone here can help me with the following.
我对 VBA 还很陌生,希望这里有人可以帮助我解决以下问题。
I have an internal web page with a long, unordered HTML list.
Out of this list I need to find a specific <li>
tag with a certain ID and then click a link / anchor tag within this list tag.
我有一个内部网页,里面有一个很长的、无序列表的 HTML 列表。在此列表中,我需要找到具有特定<li>
ID的特定标签,然后单击此列表标签中的链接/锚标签。
The part of the source code looks as follows:
源代码部分如下所示:
<li id="limitation_type_val531" onclick="show_limitation_subtype(this.id,'150',' SG KYC ','31','3');">
<img src="/images/icon_sel_tick.gif" id="selected_limitation_type_val531" style="display:none;clear:both;"/>
<a href="#subtype_section" style="text-decoration:none; color:#000;"> My Target </a>
<p class="add_arrow_right"> ></p>
</li>
The anchor tag in question does not have a name or ID but is the only anchor tag within this <li>
tag and has a fixed text (" My Target ").
有问题的锚标记没有名称或 ID,但它是此<li>
标记中唯一的锚标记,并且具有固定文本(“我的目标”)。
Can someone tell me how I can simulate a click on this using VBA ?
有人能告诉我如何使用 VBA 模拟点击吗?
My thought was to refer to the <li>
ID as follows but I don't know how to simulate the click on the anchor tag then:
我的想法是将<li>
ID引用如下,但我不知道如何模拟对锚标记的点击:
Set ObjA = ie.Document.getElementByID("limitation_type_val531").getElementsByTagName("a")
Many thanks for any help with this, Tim.
非常感谢您对此的任何帮助,蒂姆。
回答by Santosh
Give this a try
试试这个
Set ObjA = ie.Document.getElementByID("limitation_type_val531").getElementsByTagName("a")(0)
ObjA.Click