I've next structure :
<div id='list'>
<div class='column'>aaa</div>
<div class='column'>bbb</div>
...
<div class='column'>jjj</div>
</div>
I was wonder if there is a ways to use XPath, and to write some query were I can get the index of the requested element within the "list" element.
I mean that I'll ask for location of class='column'
where the text value is aaa
and I'll get 0
or 1
...
Thanks
In index, we can write the expression of XPath with the braces, and then we can write the index outside into the braces. It is defined as per specific nodes within the node-set for XPath index by using selenium webdriver.
We can select specific nodes within xpath node sets by index with Selenium webdriver. We can mention a specific node with the help of its index number enclosed in []. Let us have a look at the below html code for an element having children. The element with tagname ul has multiple child elements with tagname li.
Note also, index values in XPath predicates (technically, 'proximity positions' of XPath node sets) start from 1, not 0 as common in languages like C and Java.
You could just count the div elements preceding the element you're looking for:
count(div[@id = 'list']/div[@id = 'myid']/preceding-sibling::div)
You can count
the preceding siblings:
count(//div[@id="list"]/div[@id="3"]/preceding-sibling::*)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With