Reputation: 40633
Assume the following HTML DOM:
<table id="my_id">
<tbody>
<tr>
<th>Location:</th>
<td>
1600 Parkway Ave
Los Angels
California
</td>
</tr>
</tbody>
</table>
How do I get '1600 Parkway Ave Los Angels California' assuming there are a lot of <tr>
in this table? I think I need to get the sibling of the <th>
that contains Location:
. I've been trying to do something like:
//*[@id="my_id"]//th[Text()='Location:']
Upvotes: 0
Views: 40
Reputation: 52848
You could move the th
predicate up to tr
...
//*[@id="my_id"]//tr[th='Location:']/td/text()
Update based on comment The "Location:" string actually has whitespace around it.
:
//*[@id="my_id"]//tr[normalize-space(th)='Location:']/td/text()
Upvotes: 3
Reputation: 157937
As simple as:
//*[@id="my_id"]//th[text()='Location:']/../td/text()
Upvotes: 0