Home > DeveloperSection > Forums > How to Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed
Pawan Shukla
Pawan Shukla

Total Post:29

Points:203
Posted on    February-03-2015 11:14 PM

 Mobile Development Android  Selenium 
Ratings:


 1 Reply(s)
 1694  View(s)
Rate this:

I am working on Protractor with Android hybrid app. I am trying to count the elements and Retrieve and display all the elements. I am able to get the count of the elements. But when I try to display, the For loop is not getting executed, nor gives any Error.

Kindly Advise. Here's my code 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);

       })

     }

  });



Allen Scott

Total Post:41

Points:289
Posted on    February-03-2015 11:28 PM

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);

    });

  });


Don't want to miss updates? Please click the below button!

Follow MindStick