Question

I am writing relational xpath i need this code to fetch "Tax" Location

<td id="td26" style="width: 16%">
<div class="bglabel" style="width: 150px; clear: both">
Tax 
<div style="float: right;">
</div>
</td>

Xpath Code which i have written

td[div[text()='Tax ']] - Not Working
td[div[contains(text(),'Tax')]] - Not Working 
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top