<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;
}
答案 0 :(得分: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;
}
}
答案 1 :(得分:0)
使用xpath
第一个单选按钮//input[@id='rightsTokenOid']and position()=1
第二个单选按钮//input[@id='rightsTokenOid']and position()=2
答案 2 :(得分: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;
}