我有一个可以处理Internet explorder的脚本(即),我需要循环选择字段,这是4个元素具有相同ID(在同一页面上)的zelf是没有问题的。

我如何让它遍历4个字段?
我可以让它们更具体吗?

我使用的代码如下:

ie.document.getElementByID("DownloadImage").Click


ie代码如下:
领域1

<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a>




领域2

<a id="DownloadButton" href="javascript:__doPostBack('ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadButton','')">CZ_Specificatie_150005697.pdf</a><input name="ctl00$ctl00$MainContent$MainContent$ctl00$declaratiebestandView$RetourInformatieGrid$ctl03$DownloadImage" class="inlineButton" id="DownloadImage" type="image" src="../images/download.png" text="CZ_Specificatie_150005697.pdf">


然后打开下载屏幕,然后我的代码继续运行(并可以:))

最佳答案

您可以使用querySelectorAll来收集它们的所有元素,这些元素具有id属性,其值与您所追求的相符。您可以通过索引区分它们。即使ID重复,此方法也允许您收集它们。但是,您共享的HTML会下载同一文档,因此似乎不需要循环。

Dim nodeList As Object, i As Long
Set nodeList = ie.document.querySelectorAll("[id=DownloadButton]")
For i = 0 to nodeList.Length-1
    nodeList.item(i).Click
Next


这会循环所有匹配的元素并单击

通过索引将是特定的,但是如果您熟悉CSS选择器,则可以使用很多方法来指定元素。

10-06 16:06
查看更多