Reputation: 317
<table>
<tr>
<th class="a">Name</th>
<th class="b">Old </th>
<th class="x">New</th>
</tr>
</table>
In the above snippet using X-path,I need to get the index of the "th"w.r.to "tr" node which is 3.How can I achieve this?
I tried to find the node using
//aside//table//tr/th[text() = 'New']
But I do not know to find it's relative index
Is there any axis-specifier to get the index of it?
Upvotes: 3
Views: 549
Reputation: 52685
Try below XPath to get node index:
//table//tr/th[text() = 'New']/count(preceding-sibling::th) + 1
Upvotes: 2