PowerShell的IE自动化的getElementById有多个条目(powershell IE automation getElementByID with multiple entries)

.NET Framework IT屋
问 题

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
$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!


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.

本文地址:IT屋 » powershell IE automation getElementByID with multiple entries

问 题


  $ SURL =某些URL
$ IE =新的对象-com“InternetExplorer.Application”
$ ie.visible = $真
$ ie.navigate($ SURL)
$ doc的= $ ie.Document
$元= $ doc.getElementByID(“some_name []”)





这是HTML ID必须是唯一的!所以这就是为什么你只有一次。

来源: http://www.w3schools.com/tags/att_standard_id.asp




  而由JavaScript(通过HTML DOM)来操纵的元素

按照的getElementById 文件:



使用 getElementsByClassName getElementsByName 或<一个HREF =“htt​​p://msdn.microsoft.com/en-us/library/ie/ms536439%28v=vs.85%29.aspx”相对=“nofollow”>的getElementsByTagName 来代替。

本文地址:IT屋 » PowerShell的IE自动化的getElementById有多个条目