使用xpath,我有一个表,其中每个单元格上都包含span,我试图选择一个在col2处具有空keyup
的按钮。如何选择呢?
<span>
我尝试过:
+-------+------+------+--------+
| col 1 | col2 | col3 | button |
+-------+------+------+--------+
| col | f | ch | select |
| col | | ch | select |
| col | 2 | ch | select |
| b | n | ch | select |
+-------+------+------+--------+
和
//span[text()="col"]/following::span/[text()='']following::span/[text()="ch"]/following::a[text()="select"][1]
但我不知道第二个//span[text()="col"]/following::span[normalize-space()]/following::span[text()="1"]/following::a[text()="select"][1]
的内容,因为该范围不包含任何内容。只是span/[text()='']
答案 0 :(得分:1)
您可以尝试在XPath下面选择仅包含2个非空跨度的表行中的链接:
//tr[count(.//span[text()])=2]//a[.="Select"]
如果您需要第二行为空的表行中的链接:
//tr[(.//span)[2][not(text())]]//a[.="Select"]
或更适合您的情况:
//tr[(.//span)[1] = "col" and (.//span)[3] = "ch" and (.//span)[2][not(text())]]//a[.="Select"]