首页 > 解决方案 > 计算返回的子项数并使用赛普拉斯将子项属性推送到数组中

问题描述

我正在尝试计算返回的孩子数量

cy.xpath(NODE_PREVIEW_PANEL).children('data-testid')

这样我就可以使用计数将所有值依次传递到数组中,从而避免.each()函数的异步。

我怎样才能在这里得到孩子的数量?

(或者你可以提出一个完全不同的解决方案)

标签: javascripteachcypresschildren

解决方案


您可以使用索引值来查找元素的位置。您可以执行以下操作:

cy.xpath(NODE_PREVIEW_PANEL).children('data-testid').each((el, index) => {
    //It will give the position of the element  
    Array.push(index);
})

推荐阅读