Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

xpath

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

like image 913
KClough Avatar asked Jan 05 '11 19:01

KClough


2 Answers

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'

like image 72
Dimitre Novatchev Avatar answered Oct 19 '22 07:10

Dimitre Novatchev


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

like image 26
stefan.natchev Avatar answered Oct 19 '22 07:10

stefan.natchev