Reputation: 736
let's say I have a html structure like this -> (note: in my code there are no IDs, i just put them here so it's easier to explain)
<body>
<table id=a>
<tr>
<td>
<table id=b>
<tr>
<td>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table id=c>
<tr>
<td>
</td>
</tr>
</table>
</body>
Using XPath, //body/table[1]
gives me the inner table with the id "b", but what I really want is it's first child ("c"). Something along th lines of $("body >table").eq(1)
but i'm using c#. How do I do that using XPath?
Tnx!
EDIT: it is not an option me to select the [2] element, since this is only a simplified explanation of the problem i'm heaving...
Andrej
Upvotes: 0
Views: 1520
Reputation: 4361
The element selectors starts from index 1 (and not from 0). Hence you will have to use the xpath query //body/table[2]
Here is the explanation with screen shots.
For 0 based index node will be null;
But since the index starts with 1, for indeces 1 and 2 these nodes will be returned
Still not convinced? Let's check for the inner table element.
First let's check with 0 based index (again it is going to be null)
However when the index is 1 it will return the correct node
Upvotes: 1