Empty nodes in HTML documents

Last edited on

When an HTML document's DOM structure is retrieved using JavaScript, the structure often contains empty nodes.

For example, given a document like this:


Squish will get a DOM structure similar to this one from the browser:

The empty nodes are called NODE1, NODE2, etc.

Here is a little example that shows how to retrieve the children of a specific object and how to remove the empty nodes from that list:

def main():
    o = waitForObject({"id": "squishplatforms", "tagName": "UL"})
    children = object.children(o)
    test.log("Child count with NODEs: " + str(len(children)))
    children2 = removeNODEs(children)
    test.log("Child count without NODEs: " + str(len(children2)))

def removeNODEs(objs):
    res = []
    for o in objs:
        if hasattr(o, "tagName") and o.tagName != "undefined":
    return res

Expected output:

Child count with NODEs: 17

Child count without NODEs: 8