当我试图检查条件是否单击了复选框时。 但是当条件为真或假时,它只显示else(false)部分。
HTML
:
<tr class="ui-widget-content ui-datatable-even ui-datatable-selectable ui-state-highlight" data-ri="0" data-rk="69022768" role="row" aria-selected="true">
<td class="ui-selection-column" role="gridcell" style="width: 34px; text-align:center">
<div class="ui-chkbox ui-widget">
<div class="ui-helper-hidden-accessible">
<input name="identititesSelect:tabView:searchResultsTable_checkbox" type="checkbox">
</div>
以下是我尝试过的代码:
WebDriverWait wait = new WebDriverWait(d1, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='ui-helper-hidden-accessible']/input[@type='checkbox']")));
if (element.isSelected())
{
System.out.println("true");
}
else
{
System.out.println("false");
}
答案 0 :(得分:1)
你使用错误的选择器。 XPath
应如下:
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath('//div[@class="ui-helper-hidden-accessible"]/input[@type="checkbox"]')));
如果选中复选框,您还可以检查属性aria-selected
,true
,否则false
WebElement element = d1.findElement(By.xpath("tr[@class='ui-widget-content ui-datatable-even ui-datatable-selectable']"));
if (element.getAttribute('aria-selected').equals('true'))
{
System.out.println("true");
}
else
{
System.out.println("false");
}