COUNT()VS在量角器长度 [英] count() vs length in Protractor

查看:149
本文介绍了COUNT()VS在量角器长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据该文件,有2种方式来获得多少元素是 ElementArrayFinder (即 element.all结果里面()调用):


  • $$(MyClass的)。长度,记录的这里


  

...数组有长度等于长度的<$ C $发现的元素C> ElementArrayFinder 和每个结果再presents元素上执行操作的结果。



  • $$(MyClass的)。COUNT(),记录的这里


  

重新计数$ P $元素由psented的数量 ElementArrayFinder


什么是这两种方法,哪一个应该是preferred区别?


解决方案

$$(MyClass的)。长度

需要解决的承诺,以获得正确的元素的长度。

// WORK
$$(MyClass的)。然后(功能(项){
  items.length;
});//不工作
$$(MyClass的)的长度。


$$(MyClass的)。COUNT()

一个用于包装$$('MyClass的')。长度这是一个承诺本身并不需要解决,比如的承诺。长度

  $$(MyClass的。)计数()。



  

其中之一应该是preferred?


除非有定位时,一些复杂的业务 $$(MyClass的)。然后(功能(项){...} )涉及然后 items.length 将提供更好的性能。否则 $$(MyClass的)。COUNT()应始终使用。

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

  • $$(".myclass").length, documented here:

...the array has length equal to the length of the elements found by the ElementArrayFinder and each result represents the result of performing the action on the element.

  • $$(".myclass").count(), documented here:

Count the number of elements represented by the ElementArrayFinder.

What is the difference between these two methods and which one should be preferred?

解决方案


$$(".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.

这篇关于COUNT()VS在量角器长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆