I'm trying to find a node ANYWHERE in the HTML document after a specified other node occured. Not only in siblings and childs but also very far cousins. This is basically a linear search through the HTML document from a certain point, which I know is somehow against the hierachicyl nature of xpath.
I need this for a page with two very similar tables where I want to address the second one.
Here is a simplified example
<div>
<div>
<title>Table1</title>
</div>
</div>
<table>
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Val1</td>
<td>Val2</td>
</tr>
</tbody>
</table>
<div>
<div>
<title>Table2</title>
</div>
</div>
<table>
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
</tr>
</thead>
<tbody>
<tr>
<td>OtherVal1</td>
<td>OtherVal2</td> (==>This is the element I want)
</tr>
</tbody>
</table>
This example would of course make it ease to do
//title[text()='Table2']/../../following-sibling::table/tbody/tr/td[2]
(like suggested in this topic)
or maybe
//table[2]/tbody/tr/td[2]
But the real document I'm working with has far more <div>
's and other tags. Still the most natural way to distinguish the two tables is the title.
This is why I would like to do something like this:
//title[text()='Table2']/[parseWholeCodeAfterThis]/table/tbody/tr/td[2]