0
<tr class="odd">
<td>
<input id="rightsTokenOid" type="radio" value="rightsTokenOid" onclick="setRightsTokenOid('urn:dece:rightstokenid:org:dece:E9807B96D4153534E040A8C0158E4EB8');" style="width:100%;border:0px" name="rightsTokenOid">
</td>
<td>urn:dece:rightstokenid:org:dece:E9807B96D4153534E040A8C0158E4EB8</td>
</tr>
<tr class="even">
<td>
<input id="rightsTokenOid" type="radio" value="rightsTokenOid" onclick="setRightsTokenOid('urn:dece:rightstokenid:org:dece:EA07E75226B329B1E040A8C0158E1813');" style="width:100%;border:0px" name="rightsTokenOid">
</td>
<td>urn:dece:rightstokenid:org:dece:EA07E75226B329B1E040A8C0158E1813</td>
</tr>

我使用以下方法单击单选按钮,但它不起作用。请建议我使用以下方法单击所需单选按钮的方法

String RightsTokenID = urn:dece:rightstokenid:org:dece:EA07E75226B329B1E040A8C0158E1813;

List<WebElement> radios = driver.findElements(By.name("rightsTokenOid"));

for (WebElement element : radios) {

    if (element.getAttribute("value").equals(RightsTokenID)) {
       element.click();
    }
    break;
}
4

3 回答 3

0

那这个呢?将 onclick 视为一个属性,看看它的值是否具有正确的标记?

String RightsTokenID = urn:dece:rightstokenid:org:dece:EA07E75226B329B1E040A8C0158E1813;

List<WebElement> radios = driver.findElements(By.name("rightsTokenOid"));

for (WebElement element : radios) {

    if (element.getAttribute("onclick").contains(RightsTokenID)) {
       element.click();
    }
break;
}
于 2013-11-01T06:02:03.197 回答
0

使用 position() 的帮助xpath

第一个单选按钮的 xpath//input[@id='rightsTokenOid']and position()=1

第二个单选按钮的 xpath//input[@id='rightsTokenOid']and position()=2

于 2013-10-31T09:00:37.847 回答
0

name,id并且value对于两个单选按钮是相同的。尝试赋予他们独特的价值。

编辑:尝试比较onclick

String RightsTokenID = "urn:dece:rightstokenid:org:dece:EA07E75226B329B1E040A8C0158E1813";

List<WebElement> radios = driver.findElements(By.name("rightsTokenOid"));

System.out.println("listsize: " + radios.size());
for (WebElement element : radios) {
    // just for debugging regarding this question
    System.out.println("tagname: " + element.getTagName());
    System.out.println("name: " + element.getAttribute("name"));
    System.out.println("type: " + element.getAttribute("type"));
    System.out.println("value: " + element.getAttribute("value"));
    System.out.println("onclick: " + element.getAttribute("onclick"));

    if (element.getAttribute("onclick").contains(RightsTokenID)) {
        element.click();
        break;
    }
}
于 2013-10-31T08:38:03.623 回答