Pages

How to get the total count of list of elements ?

count() in protractor ?

>> In protractor, we can get total count of matching elements using count() function.

Please check below code script:

First write xpath with help of DOM

count() in protractor
count()


Here we have 3 radio buttons, we can match using locator.

describe('Protractor - count()', function () {
it('Code script to use count() in protractor', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var multipleElements = element.all(by.css("input[type='radio']"));

var elementsCount = getCount(multipleElements);

elementsCount.then(function (value) {
console.log("Total Count=" + value);
});
});

function getCount(element) {
return element.count().then(function (totalElementsFound) {
console.log("No of elements Found=" + totalElementsFound);
return totalElementsFound;
});
}
});

Output:
It will return total number of matching elements found.
protractor count()
count()
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.