javascript - 当我们要检查该类是否存在时,如何使用条件语句?
问题描述
在赛普拉斯中,我想创建一个条件来检查是否创建了一个类,如果是,则执行相同的步骤。
我在以下位置看到了一个文档:
https://docs.cypress.io/guides/core-concepts/conditional-testing.html#AB-campaign
我写了一个例子:
cy.get('.footerWrapper').then((div) => {
if (div.find('.TestClass')) {
cy.log('xxx')
} else {
cy.log('yyy')
}
})
但是条件总是正确的,即使我使用 find() 和 children() 并且“TestClass”类不存在。“TestClass”是“footerWrapper”类的孩子
应该怎么写?有谁有想法吗?
解决方案
您应该检查该.length
属性,因为空数组 [] 总是true
在“if”条件内给出。
cy.get('.footerWrapper').then((div) => {
if (div.find('.TestClass').length) {
cy.log('xxx')
} else {
cy.log('yyy')
}
})
推荐阅读
- mongodb - 如何在 mongo-atlas 中添加 `killOp` 权限?
- hyperledger-fabric - 使用 TLS 将链码作为外部服务:已安装但查询未找到?
- javascript - 只让最后一个 API 调用通过
- android - 带有不同尺寸图像的android tensorflow静态图像分割问题
- image - CreateScaledBitmap 方法在调整图像大小时返回模糊图像
- ios - 如果我将我的 iOS 应用目标从 iOS 11 升级到 iOS 13,13 之前的用户会发生什么情况?
- python - Python:如何编写通用脚本并避免硬编码字符串?
- visual-studio-code - VisualStudio Code Javascript IntelliSense 在导出或导入时中断
- c - Cygwin 未在 C 中显示任何输出
- npgsql - 在 npgsql 级别将布尔值转换为位