---
title: "How to Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed"  
description: "How to Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed"  
author: "Anonymous User"  
published: 2015-02-03  
updated: 2015-02-03  
canonical: https://www.mindstick.com/forum/12938/how-to-protractor-counting-the-no-of-elements-and-display-all-the-elements-with-for-loop-is-not-getting-executed  
category: "mobile development"  
tags: ["android", "selenium"]  
reading_time: 1 minute  

---

# How to Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed

I am working on Protractor with [Android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [hybrid](https://answers.mindstick.com/qa/30573/what-is-hybrid-network) app. I am [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) the [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) and [Retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) and display all the elements. I am able to get the count of the elements. But when I try to display, the [For loop](https://www.mindstick.com/forum/12568/android-for-loop-not-working-in-main-thread) is not getting executed, nor gives any Error.

Kindly Advise. Here's my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) below.

```
   var n1 = browser.element.all(by.className('program-details-directive-container')).count();  browser.element.all(by.className('program-details-directive-container')).  then( function(n1)   {    for(var i=0; i<n1;++i)    {      n1(i).getText().then(function(text1)      {       console.log(text1);       })     }  });
```

## Replies

### Reply by Allen Scott

It looks the promise chain is not continuing try the following with the help of bluebird

```
  var Promise = require('bluebird');   var n1 = browser.element.all(by.className('program-details-directive-container')).count();  browser.element.all(by.className('program-details-directive-container'))    .then(function(n1) {      var promises = n1.map(function(elm){        return elm.getText().then( function(text1) {          console.log(text1);        })      });       return Promise.all(promises);    });  });
```


---

Original Source: https://www.mindstick.com/forum/12938/how-to-protractor-counting-the-no-of-elements-and-display-all-the-elements-with-for-loop-is-not-getting-executed

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
