Jump to content
Sign in to follow this  

HTML DOM .attributes

Recommended Posts


Anyone know of the syntax to filter html down by attribute name/value in a single line?

Currently, first I search for a element by name, loop through that for a specific attribute name/value, and then use that as the parent object to continue my search. I'd like to be able to do that in one line, using .attributes

$test = $oIE.Document.getElementsByTagName('div')
;ConsoleWrite ( $test.length & @CRLF )
For $node in $test
 If $node.Attributes("class").value = "welcome" Then
  $oCorrectNode = $node
$oCorrectNode = $oCorrectNode.getElementsByTagName('span')
For $node in $oCorrectNode
 ConsoleWrite ( $node.innerHTML & @CRLF )

In the end, I would prefer something like this, if possible:

$node = $oIE.document.getElementsByTagName('div').attributes('[class=welcome]').getElementsByTagName('span')

currently, i can do this to drill down by only elements:

$node = $oIE.document.getElementsByTagName('div').item().getElementsByTagName('span').item(0)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post

Link to post
Share on other sites

$nodeobject.getAttribute('attribute').value ; for get attributes

in you situation you can use

$nodeobject.className, it returns the class attribute

Edited by salvobellino95

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this