Luiz Henrique Rios
Luiz Henrique Rios

Reputation: 13

XPath with HTML

I have a html like this

<tr>
<td>
<div>Text1</div>
</td>
</tr>
<tr>
<td>
<div>Text2</div>
</td>
</tr>
...

I want to find Text1 with XPath, If i use this XPath //tr[td/div[text()='Text1']]

It works but if I try this //tr[//div[text()='Text1']] doesn't works, returns every <tr> in the document even if //div[text()='Text1'] only returns one.

I would like to know why it happens.

Thanks

Upvotes: 0

Views: 50

Answers (1)

Theo
Theo

Reputation: 157

When you use //tr, xpath is searching for all the <tr> occurences. If you add [something] after this, it is searching if this something exists inside the current <tr> in the search loop. But if you use //something, the doubl it means search in the whole document. //something is always found so for each <tr> the condition is respected.

Upvotes: 1

Related Questions