Pablo Fernandez
Pablo Fernandez

Reputation: 287410

Two levels of contains in an XPath

I have this XPath:

//tr[contains(td, 'Europe')]

which was working when I had this:

<tr>
  <td></td>
  <td>Europe</td>
  <td></td>
</tr>

but now I have this:

<tr>
  <td></td>
  <td><a>Europe</a></td>
  <td></td>
</tr>

How can I get with an XPath now (based on the fact that Europe is in there).

I tried:

//tr[contains(a, "Europe")]

and

//tr[contains(text(), "Europe")]

and many other silly things without any success.

Upvotes: 0

Views: 823

Answers (1)

user357812
user357812

Reputation:

//tr[contains(td, 'Europe')]

This should work with both schema because fn:contains() cast both arguments to strings.

I do see a problem with a different schema where there can be more than one td element. For that case you should use:

//tr[td[contains(.,'Europe')]]

Upvotes: 4

Related Questions