powershell IE automation getElementByID with multiple entries

风格不统一 提交于 2019-12-23 05:29:19

问题


this only gets the first of the elements, though the backend cgi (such as php) can get all these in an array.

$surl=some url
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($surl)
$doc = $ie.Document
$element = $doc.getElementByID("some_name[]")

this only gets the first of the elements with the same name.

i am trying to fill values with a script but so far have not figured out a way to go beyond the first of these elements. i do not control the document rendering so cannot change how these are named.

thanks for any ideas!


回答1:


An HTML ID has to be unique! So that's why you only get one.

From: http://www.w3schools.com/tags/att_standard_id.asp

The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).

The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.

Per the getElementById documentation:

Returns a reference to the first object with the specified value of the ID or NAME attribute.

Use getElementsByClassName or getElementsByName or getElementsByTagName instead.



来源:https://stackoverflow.com/questions/9435616/powershell-ie-automation-getelementbyid-with-multiple-entries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!