javascript - TestCafe 条件 if else web 元素如果第一个失败,如何继续下一个条件
问题描述
if (btnSubmit.exists) {
await t
.click(btnSubmit) //this failed due to button not exist actual is stopped in here
} else if (buttonOK.exists) {
await t
.click(buttonOK) //i want to continue to execute this button which is exist
} else {
console.log("foo")
}
我有这样的简单代码,如果第一个条件未找到 web 元素,则运行自动化,然后继续下一个条件,但实际是保持失败并在第一个条件下停止。
解决方案
尝试,
if (await btnSubmit.exists) {
await t.click(btnSubmit)
} else if (await buttonOK.exists) {
await t.click(buttonOK)
} else {
console.log("foo")
}
推荐阅读
- javascript - 无法将 event.target 转换为字符串
- python - 相当于 Python 中的 evrnd(mu,sigma,m,n)
- git - 为什么 Heroku 每次都要安装这么多模块?
- c# - 如何在 ASP.NET Core 3.0 中使用 ValidationAttribute 验证多个操作参数
- css - 如何使用溢出使嵌套表在移动设备中可滚动:滚动无混蛋
- wordpress - Roots Sage 9 的高级自定义字段范围问题
- angular - Angular Material Stepper,动态颜色变化
- react-native - 运行模拟器导致无限下载
- c# - 任务
总是返回 null - c# - 我如何确定网站中是否有特定的文本 with Selenium