count() vs length in Protractor

后端 未结 1 1353
不思量自难忘°
不思量自难忘° 2021-01-05 02:33

According to the documentation, there are 2 ways to get how many elements are inside the ElementArrayFinder (the result of element.all() call):

相关标签:
1条回答
  • 2021-01-05 03:12

    $$(".myclass").length

    Need to resolve the promise to get the length of element correctly.

    // WORK
    $$(".myclass").then(function(items){
      items.length;
    });
    
    // DOES NOT WORK
    $$(".myclass").length; 
    

    $$(".myclass").count()

    A wrapper for $$('.myclass').length which being a promise itself and doesn't require to resolve promise like .length

    $$(".myclass").count(); 
    

    which one should be preferred?

    Unless there some complex business when locating $$(".myclass") and .then(function(items){...}) involved then items.length will give better performance.

    Otherwise $$(".myclass").count() should always be used.

    0 讨论(0)
提交回复
热议问题