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

HtmlXpath

Html Problem Overview


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

Html Solutions


Solution 1 - Html

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'

Solution 2 - Html

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 /..

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKCloughView Question on Stackoverflow
Solution 1 - HtmlDimitre NovatchevView Answer on Stackoverflow
Solution 2 - Htmlstefan.natchevView Answer on Stackoverflow