You could use a selector that includes the ".ng-not-empty" or "ng-empty" class:
List<WebElement> eltsUnchecked = driver.findElements(By.cssSelector("input[ng-model='checkboxModel.value1'].ng-empty"));
bool isNotCheched = eltsUnchecked.size() > 0;
if (isNotCheched) {
// check the checkbox
eltsUnchecked.get(0).click();
}
List<WebElement> eltsChecked = driver.findElements(By.cssSelector("input[ng-model='checkboxModel.value1'].ng-not-empty"));
bool isCheched = eltsChecked.size() > 0;
if (isCheched) {
// uncheck the checkbox
eltsChecked.get(0).click();
}
Or by checking the presence of ".ng-not-empty" or "ng-empty" in the class attribute :
WebElement checkbox = driver.findElement(By.cssSelector("input[ng-model='checkboxModel.value1']"));
bool isCheched = checkbox.getAttribute("class").contains("ng-not-empty");
bool isNotChecked = checkbox.getAttribute("class").contains("ng-empty");
if (isCheched) {
// uncheck the checkbox
checkbox.click();
} else if (isNotChecked) {
// check the checkbox
checkbox.click();
}
But if you are using the "checked" attribute instead then:
WebElement checkbox = driver.findElement(By.cssSelector("input[ng-model='checkboxModel.value1']"));
bool isCheched = checkbox.getAttribute("checked").length > 0;
bool isNotChecked = checkbox.getAttribute("checked").length == 0;