The accepted answer changes OP's intended logic.
What OP's trying to do is to find div
with text "Tax" inside a td
, therefore OP's own answer is on the right track, the accepted answer isn't.
//div[contains(text(),'Tax')]
locates it anywhere in DOM, which is likely to cause trouble.
What OP wants is (using .
to specify current node):
//td[./div[contains(text(),'Tax')]]
Imagine there is another div
also contains text "Tax", //div[contains(text(),'Tax')]
will find the one OP doesn't want.
<div>Tax table</div>
<table>
<tr>
<td id="td26" style="width: 16%">
<div class="bglabel" style="width: 150px; clear: both">Tax <div style="float: right;"></div></div>
</td>
</tr>
</table>
@Santhosh.S: Hope this makes sense to you.