1

我有一个带有表格的 xhtml 页面。通常其中一个在单元格中有文本“针文本”。如何获得这样的所有表格?

<table class="content_table">
  <tr>
    <td>Column 1</td>
    <td>Column 2</td>
  </tr>
  <tr>
     <td>Value 11</td>
     <td>Value 21</td></tr>
  <tr>
    <td><a href="link.html">needle text</a></td>
    <td>Value 22</td>
  </tr>
</table>

注意:表格可以带有标签:thead、th 等。

  1. 从 xhtml 页面收集所有表格 - 使用"//*[@class='content_table']".
  2. 找到带有文本的节点,但没有成功。我试过了,
    //alink[text() = "needle text"]但结果是空的。
  3. 在父树的父级中查找表作为祖先。
    //alink[text() = "needle text"]/..
4

1 回答 1

2

你可以试试下面的XPATH

//a[.='needle text']/ancestor::table[1][@class='content_table']

或者

//table[@class='content_table' and .//a[.='needle text']]
于 2013-10-17T11:00:36.450 回答