首页 > 解决方案 > 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 元素,则运行自动化,然后继续下一个条件,但实际是保持失败并在第一个条件下停止。

屏幕

标签: javascripttestingautomated-testse2e-testingtestcafe

解决方案


尝试,

    if (await btnSubmit.exists) {
        await t.click(btnSubmit)
    } else if (await buttonOK.exists) {
        await t.click(buttonOK)
    } else {
        console.log("foo")
    }

推荐阅读