count() vs length in Protractor(量角器中的计数()与长度)
问题描述
根据文档,有两种方法可以获取 ElementArrayFinder
中有多少元素(element.all()
调用的结果):
$$(".myclass").length
,记录在 这里:
...数组的length
等于ElementArrayFinder
找到的元素的length
,每个结果代表执行的结果对元素的操作.
$$(".myclass").count()
,记录在 这里:
计算ElementArrayFinder
所代表的元素个数.
这两种方法有什么区别,应该首选哪一种?
$$(".myclass").length
需要解决 promise 以正确获取元素的长度.
//工作$$(".myclass").then(function(items){项目长度;});//不工作$$(".myclass").length;
<小时>
$$(".myclass").count()
$$('.myclass').length
的包装器,它本身就是一个 Promise,不需要像 .length
那样解析 Promise
$$(".myclass").count();
<小时><块引用>
应该首选哪一个?
除非在定位$$(".myclass")
和.then(function(items){...})
时涉及到一些复杂的业务,那么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 thelength
of the elements found by theElementArrayFinder
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.
这篇关于量角器中的计数()与长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:量角器中的计数()与长度


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01