Find all visible elements using Protractor
angularjs, protractor
Solution
Your filter function does not return anything, so add 'return' to link.isDisplayed():
function getVisibleDivs(driver) {
var links = driver.findElements(by.css("#MainContent div"));
return protractor.promise.filter(links, function(link) {
return link.isDisplayed();
})
.then(function(visibleLinks) {
return visibleLinks;
});
}
element.all(getVisibleDivs).then(function (items) {
console.log(items.length);
});
Problem
I am trying to the count of find all visible elements under a container using Protractor ``` function getVisibleDivs(driver) { var links = driver.findElements(by.css("#MainContent div")); return protractor.promise.filter(links, function(link) { link.isDisplayed(); }) .then(function(visibleLinks) { return visibleLinks; }); } element.all(getVisibleDivs).then(function (items) { console.log(items.length); }); ``` I always get the count as 0 though I have manually checked that the elements are present. Any pointers for debugging this much appreciated. UPDATE Some sample html ``` <html> <body> <div id="MainContent"> <div class="header"> Header </div> <div class="content"> Content </div> <div class="sidebar" style="display:none"> Sidebar </div> <div class="footer"> Footer </div> </div> </body> </html> ```