【发布时间】:2014-10-01 07:28:58
【问题描述】:
有 2 个表,我需要选择“date1”文本,该文本可能位于第一个表的 tr/td/a 或第二个表的 tr/td 中。这种场景怎么写xpath?
<div>
<table>
<tbody>
<tr>
<td id="1">
<a style="font-style:normal;font-weight:bold;" onclick="return" class="PTL"> </a>
</td>
<td id="1">
<a style="font-style:normal;font-weight:bold;" onclick="return" class="PTL">date1</a>
</td>
<td id="1">
<a style="font-style:normal;font-weight:bold;" onclick="return" class="PTL">date1</a>
</td>
<td id="1">
<a style="font-style:normal;font-weight:bold;" onclick="return" class="PTL">date2</a>
</td>
<td id="1">
<a style="font-style:normal;font-weight:bold;" onclick="return" class="PTL">date3</a>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td id="1" style="font-style:normal;font-weight:bold;" class="PTCH"> </td>
<td id="1" style="font-style:normal;font-weight:bold;" class="PTCH">date1</td>
<td id="1" style="font-style:normal;font-weight:bold;" class="PTCH">date2</td>
<td id="1" style="font-style:normal;font-weight:bold;" class="PTCH">date3</td>
</tr>
</tbody>
</table>
</div>
我试过了,但这会选择整行。我想选择一个特定的列
xpath=(//table)[2]//tr[td[contains(text(),'date1') and not(text()=' ')] or td/a[contains(text(),'date1') and not(text()=' ')]]
【问题讨论】:
-
对我投反对票。没有证据表明您自己尝试过任何事情或研究过这个主题。这个问题只是一个需求转储。
-
我对此进行了大量研究,但无法找到解决方案。你能看看这个
-
@udeshplus 您说您想选择
date1文本,但在您的尝试中,您选择了tr元素。你真正想做的是什么?请清楚地描述您的要求。 -
@JLRishe 我想选择“date1”文本。就我而言,有两张桌子。对象路径“tbody/tr/td/a”中的第一个表“date1”文本和对象路径“tbody/tr/td”中的第二个表。所以我需要编写一个 xpath 来使用“或”条件为两种场景选择“date1”文本。对不起我的英语不好
标签: java html xml xpath selenium-webdriver