我正在尝试在页面中找到该按钮是只读还是已启用(可点击)。做了一些动作之后。我需要在if else条件下检查这一点,以便帮助我找到解决方案。
下面是我的按钮
的html代码<div id="agent_delete"
class="btn btn_own"
ng-confirm-click="Are you sure you want to delete selected Agent(s)?"
confirm-click-title="Delete Agent"
confirmed-click="delete()"
ng-disabled="!ctrlService.canDelete || gridApi.selection.getSelectedRows().length == 0"
disabled="disabled">
<div id="agent_delete"
class="btn btn_own"
ng-confirm-click="Are you sure you want to delete selected Agent(s)?"
confirm-click-title="Delete Agent"
confirmed-click="delete()"
ng-disabled="!ctrlService.canDelete || gridApi.selection.getSelectedRows().length == 0">
答案 0 :(得分:1)
您必须使用 isEnabled(); 方法。
if(driver.findElement(By.id("agent_delete")).isEnabled()){
//button is enabled
}
else{
//button is not enabled
}
答案 1 :(得分:0)
您可以使用disabled
检查getAttribute
属性:
WebElement element = driver.findElement(By.id("agent_delete"));
if("disabled".equals(element.getAttribute("disabled"))) {
// disabled
} else {
// enabled
}
或者使用单个调用的CSS选择器:
if(driver.findElements(By.cssSelector("#agent_delete[disabled='disabled']")).size > 0) {
// disabled
} else {
// enabled
}