Because when I used testcomplete, I remember someone saying the driver implementation in jscript somehow said it searches from bottom most element and then comes to the top...

So with respect to selenium, how does the traversal happens, does it traverse from the top of the DOM ?

1 Answer 1


Selenium implements a breadth-first search, meaning it starts from the root of the DOM and walks through all immediate children. Afterwards, it goes through the children of each children.

enter image description here

Therefore, if you search for tr td on the tree below, it will find the Shady Grove node.

enter image description here

In the Inspect Element view, it would be something as

+-- table
|   +-- rows
    |   +-- tr
        |   +-- td (Shaddy Grove)
        |   +-- td (Aeloian)
    |   +-- tr
  • Is Shady grove technically the bottom most as seen via HTML? Considering when we inspect same .. there is always left to right indentation of nodes right .. so like shady grove goes on top you mean?
    – Hi X Dmf
    Commented Mar 22, 2019 at 13:24
  • It would be the top - the first option. I've added view similar to the Inspect Element - tell me if it is clearer. Commented Mar 22, 2019 at 13:41
  • 3
    It would be helpful if you would add the source of the information provided.
    – Alexey R.
    Commented Mar 22, 2019 at 14:34
  • @AlexeyR. w3.org/TR/1999/REC-xpath-19991116/#section-Location-Steps
    – PDHide
    Commented Feb 22, 2021 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.