继续未能选择JAVA上的radioButton
我的代码似乎有点不对劲,因为有时它可以在单选按钮上选择货币,有时它不工作。有没有建议通过添加计时器或其他方法来改进代码?谢谢
HTML:
id: enumTable_data
代码:
private WebElement getRowForCurrency (String currency) {
AbstractPage page = new AbstractPage();
String[] frame = {"i2ui_shell_content","rcp_content"};
page.switchToFrame(frame);
By cell = page.waitUntilPresent(By.xpath("//table[@id='enumTable_data']//nobr[text()[contains(.,'" + currency + "')]]"));
WebElement currentElement = page.browser().findElement(cell);
while(!currentElement.getAttribute("tagName").equals("TR")) {
currentElement = currentElement.findElement(By.xpath(".."));
}
return currentElement;
}
public void selectCurrency (String currency) {
// find the text and get the parent, that is the row that contains the radiolist
JLog.write("Select Currency: " + currency);
WebElement row = getRowForCurrency(currency);
if (row != null) {
WebElement radioButton = row.findElement(By.cssSelector("input[type='radio']"));
if (null == radioButton) {
JLog.error("Found Document Row, but unable to find document radio button: " + currency, TakeScreenshot.True);
return;
}
radioButton.click();
} else {
JLog.error("Unable to find currency: " + currency, TakeScreenshot.True);
}
}
# 1 楼答案