I have similiar structure to:
<tr>
<td>I WANT THIS</td>
<td>
<a class="unread">text</a>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<a class="read">text</a>
</td>
<td></td>
</tr>
And I need to select <tr>
node, which have <a>
node with attribute [@class='unread']
, to select inner <td>
later.
I tried //tr[a/@class='unread']
and //tr/a[@class='textMsg unread']
but didn't work. How can I get my <tr>
node?
a
tag is not a child of tr
tag, you can try this xpath:
//tr[.//a/@class='unread']
Or
//tr[descendant::a/@class='unread']
To select the wanted td
element(s), use:
//tr//td[.//a[@class = 'unread']]
If it is known that the td
is a child of the tr
and the a
is a child of the td
, the above may be simplified to:
//tr/td[a[@class = 'unread']]
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