我有两个几乎相同的表格,唯一的区别是第一个表格中有一个输入标签:
表格 #1
<table>
<tbody>
<tr>
<td>
<div>
<input type="text" name="" value=""/>
</div>
</td>
</tr>
</tbody>
</table>
表格 #2
<table>
<tbody>
<tr>
<td>
<div></div>
</td>
</tr>
</tbody>
</table>
</body>
当我使用这个XPath
//table//tbody//tr[position()=1 and contains(.,input)]
时,它返回了两个表格的第一行,而不仅仅是我期望的第一个表格的第一行。然而,这个XPath
//table//tbody//tr[position()=1]//input
返回了第一个表格中的input
。那么,我做错了什么?为什么同一个
input
与两个表格相关联?我是否在这里错误地使用了.
?
tr[contains(.,input)]
的作用,我认为谓词将始终评估为 true。你同意吗? - kjhugheschild::input
出现 0 次、1 次还是多次,tr[contains(.,input)]
的谓词都必然为真,因为tr
的字符串值必然包含空字符串(0 情况)、它唯一的child::input
的字符串值(1 情况)或其第一个child::input
的字符串值(多情况)。 - kjhughescontains(。,input)
会出错。 - Michael Kay