If you want to determine if an element is displayed, the isDisplayed()
function can be utilized. Similarly, the isSelected()
function can be used to check if an element is checked. In a scenario where there are multiple checkboxes, one in each cell, here's a method to verify them -
var elements = element.all(by.css(columncssname));
var checkboxElement = $('SUB_LOCATOR_FOR_EACH_CHECKBOX_IN_CELL');
elements.each(function (cell, index) {
expect(cell.checkboxElement.isDisplayed()).toBe(true); //Confirm checkbox visibility
cell.checkboxElement.isSelected().then(function(selected){
if(selected) console.log('Element Selected'); //Prints element selection confirmation to console
});
});
Another approach to checking if an element is checked involves using the filter()
function in combination with the count()
method to determine the number of checked checkboxes. Here's how it can be done -
var checkboxElement = element.all(by.css('LOCATOR_FOR_ALL_CHECKBOXES')); //Use a universal locator for all checkboxes instead of a sub-locator specific to table cells
checkboxElement.filter(function(eachCell){
return eachCell.checkboxElement.isSelected().then(function(selected){
return selected;
});
}).count().then(function(count){
console.log(count); //Displays the count of checked elements
});
I hope this information proves beneficial.