KClough
KClough

Reputation: 2089

XPath to select a table row that has a cell containing specified text

How do I select a table row that has a cell containing specified text with XPath?

Upvotes: 66

Views: 65862

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

Use:

ExpressionSelectingTable/tr[td//text()[contains(., 'targetString')]]

This means:

Select every tr that is a child of any table selected by the expression ExpressionSelectingTable and that (the tr) has at least one td child that has at least one text-node descendent that contains the string 'targetString'

Upvotes: 87

stefan.natchev
stefan.natchev

Reputation: 151

To select rows with cells containing some text you would use this XPath expression:

//tr/td[normalize-space(text())="Banana"]/..

This selects any td that contains text "Banana" and then selects the parent with /..

Upvotes: 14

Related Questions