I know this question can be tricky, would take help/suggestions. if duplicate/bad , pls lemme know via comments I will delete.
I would like to understand how Selenium searches within the tree structure of a DOM.
(The reason why i asked is i switched from Testcomplete just now. Testcomplete searches from the bottom up. The bottom most elements gets searched faster. Also if there are 10 elements with same id, and we try findelement and not findallelements, it will give the bottom most element)
So Selenium - does it start from top or bottom of a tree branch?. Let's see the tree is as below
<div>
<section1>
<h1>
</h1>
<h2>
</h2>
</section1>
<section2>
<i1>
</i1>
</section2>
<section3>
<j1>
<k1 id='something'>
</k1>
</j1>
<j2>
</j2>
</section3>
</div>
I am searching for Element id = something.
- Does it first look out for
Section 1, h1
tag and then traverses down ? or it starts fromSection 3 j2
tag and starts upwards?. The reason is, in a very lengthy AngularJs page, searching for a table at the top gives faster results and a table in the bottom takes around 15 seconds almost. Second - does it search like serially ? or Vertically?.
Serially - Search
Section1, h1, h2, section2, i1
etc.Vertically - Search
Section1, section2, section3
and thenh1,h2,i1
etc.
Understanding this would go a long way in establishing a good element locator strategy.