在webdriver.io中使用相同的选择器对元素进行计数 [英] Counting elements with the same selector in webdriver.io
本文介绍了在webdriver.io中使用相同的选择器对元素进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 webdriver.io 与chai和mocha一起用于测试.
I am using webdriver.io with chai and mocha for testing.
在我的一项测试中,我需要计算页面中有多少个具有相同CSS类的元素. webdriver.io API 似乎都没有返回数组.
In one of my tests I need to count how many elements with the same CSS class are in the page. None of the webdriver.io API seems to return an array.
如何实现?
推荐答案
这是您的操作方式:
client.elements('.myElements', function(err,res) {
console.log('element count: ',res.value.length);
});
说明:使用 elements
可以根据给定的选择器获取所有元素.它返回一组webdriver元素,这些元素代表页面上现有元素的数量.
Explanation: with elements
you fetch all elements according given selector. It returns an array of webdriver elements which represents the amount of existing elements on the page.
这篇关于在webdriver.io中使用相同的选择器对元素进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文