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

How to select a table row that has a cell containing the specified text with XPath?

+42
html xpath
Jan 05 '11 at 19:00
source share
2 answers

Using

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

This means :

Select each tr , which is a child of any table selected by ExpressionSelectingTable , and that ( tr ) has at least one td child that has at least one text node containing the string 'targetString'

+59
Jan 05 '11 at 19:40
source share

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

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

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

+11
Jan 05 2018-11-11T00:
source share



All Articles