How can I print child nodes of a drop down element?

Last edited on

How can I access child nodes?

Possible problem: You have extra NODE elements.

It is worth noting that the resulting children of HTML elements vary in Squish, depending on the browser used. We

directly mirror the DOM from the browser's web page, and some browsers provide extra child

elements for text that occurs between the HTML elements — even if it is just whitespace.

Squish can't filter out NODE elements for backwards compatibility reasons. This is one reason

that it is important to tell support which browser you are testing with.

If you want to print only the selected element from your drop down element try code like this

def main():
    widget = waitForObject({"tagName": "SELECT"})
    test.log("Selected index: %d: %s" % (widget.selectedIndex,

    options = get_select_options(widget)
    for option in options:
	# print only selected elements
	if"selected") == "true":
	    test.log("Selected option: " + option.innerText)

def get_select_options(widget):
    options = []
    xpath_result = widget.evaluateXPath("//option")
    count = xpath_result.snapshotLength
    for i in range(count):
	item = xpath_result.snapshotItem(i)
    return options