【问题标题】:Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed量角器 - 计算元素数量并使用 For 循环显示所有元素未执行
【发布时间】:2015-03-04 01:44:08
【问题描述】:

我正在使用 Android 混合应用程序开发 Protractor。我正在尝试计算元素并检索并显示所有元素。我能够得到元素的数量。但是当我尝试显示时,For 循环没有被执行,也没有给出任何错误。

请多多指教。下面是我的代码。

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

【问题讨论】:

    标签: android selenium protractor appium


    【解决方案1】:

    看起来承诺链没有继续在 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);
        });
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      相关资源
      最近更新 更多