用于选择先前输入的XPath

问题描述 投票:1回答:2
<tr class="dark">
    <td width="10%" valign="top">
        <input id="b5c7704b641c4e290164831754a200d1" name="rowCheckBox" value="BCM$b5c7704b641c4e290164831754a200d1$$$ACCEPTED$Released$false" type="radio" valign="top" onclick="javascript:handlebuttons()" />
    </td>
    <td style="word-wrap : break-word ;overflow:hidden;" title="AttachmentService" width="30%" valign="top">
        <img src="images/service_released.PNG" onmouseover="javascript:showToolTip('Released',this)" onmouseout="hideToolTip()" style="padding-right:5px;" width="18px" height="18px" border="0" align="top" />AttachmentService</td>
    <td style="word-wrap : break-word ;overflow:hidden;" width="15%" valign="top">SOAP</td>
    <td style="word-wrap : break-word ;overflow:hidden;" width="15%" valign="top">Sync</td>
    <td style="word-wrap : break-word ;overflow:hidden;" width="15%" valign="top">1.17</td>
    <td width="15%" valign="top">Released</td>
    <td style="word-wrap : break-word ;overflow:hidden;" width="15%" valign="top">ACCEPTED</td>
</tr>

我正在使用硒,并且希望它单击版本'AttachmentService''1.17'之前的单选按钮>

我尝试了以下操作:

driver.findElement(By.xpath("//td[contains(@title, AttachmentService')]//preceding::input[1]"))

但是我想包含1.17,因为我们有很多AttachmentService,它们的版本不同,例如1.15,1.16,1.17

如何处理?

[[[[
您可以使用following-sibling添加具有特定版本的<td>并使用该元素中的preceding

String version = "1.17"; driver.findElement(By.xpath("//td[contains(@title, 'AttachmentService')]/following-sibling::td[.='" + version + "']//preceding::input[1]"));

使用following-sibling

driver.findElement(By.xpath("//td[following-sibling::td[@title='AttachmentService'] and following-sibling::td[text()='1.17']]/input"));

结果:

enter image description here

java selenium selenium-webdriver xpath siblings
2个回答
0
投票
您可以使用following-sibling添加具有特定版本的<td>并使用该元素中的preceding

0
投票
使用following-sibling
© www.soinside.com 2019 - 2024. All rights reserved.