javascript - 计算返回的子项数并使用赛普拉斯将子项属性推送到数组中
问题描述
我正在尝试计算返回的孩子数量
cy.xpath(NODE_PREVIEW_PANEL).children('data-testid')
这样我就可以使用计数将所有值依次传递到数组中,从而避免.each()
函数的异步。
我怎样才能在这里得到孩子的数量?
(或者你可以提出一个完全不同的解决方案)
解决方案
您可以使用索引值来查找元素的位置。您可以执行以下操作:
cy.xpath(NODE_PREVIEW_PANEL).children('data-testid').each((el, index) => {
//It will give the position of the element
Array.push(index);
})
推荐阅读
- aframe - 为自定义组件中的自定义属性设置动画
- javascript - 导航 json 文件以创建 jquery 自动完成所需的数组
- csv - 创建 Apache poi Workbook 时出现 Java 堆空间问题
- java - POS Hypercom Terminal T4230 使用 Java 串行端口通信的集成问题
- python - 将时间戳转换为 datetime.time python
- regex - 正则表达式与分支名称不匹配
- python - 我怎样才能让乒乓球的球变慢?
- python - 仅获取张量一部分的对角线元素
- android - 为什么我在 Firestore 中使用分页时总是得到空文档
- unity3d - z 轴是否保证 2D 中正确的图层排序?