XPath选择具有包含指定文本的单元格的表行

时间:2021-10-06 19:14:41

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

如何选择具有包含XPath指定文本的单元格的表格行?

2 个解决方案

#1


62  

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'

选择由表达式ExpressionSelectingTable选择的任何表的子节点的每个tr,并且(tr)至少有一个td子节点至少有一个包含字符串'targetString'的文本节点后代

#2


11  

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

要选择包含某些文本的单元格的行,您将使用此XPath表达式:

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

// TR / TD [正常化空间(文本())= “香蕉”] / ..

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

这将选择任何包含文本“Banana”的td,然后用/选择父级。

#1


62  

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'

选择由表达式ExpressionSelectingTable选择的任何表的子节点的每个tr,并且(tr)至少有一个td子节点至少有一个包含字符串'targetString'的文本节点后代

#2


11  

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

要选择包含某些文本的单元格的行,您将使用此XPath表达式:

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

// TR / TD [正常化空间(文本())= “香蕉”] / ..

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

这将选择任何包含文本“Banana”的td,然后用/选择父级。