【问题标题】:Protractor click if displayed is not working using async await如果显示的量角器单击使用异步等待不起作用
【发布时间】:2018-02-19 10:55:43
【问题描述】:

如果显示的量角器单击使用异步等待不起作用。我试过以下方法:

public static async clickIfDisplayed(targetElement: ElementFinder) {
    if (await targetElement.isPresent() && await targetElement.isDisplayed()) {
        await PageHelper.click(targetElement);
    }
}

即使元素不存在或不显示,上述内容有时也会点击。请帮助了解我在哪里出错了。

【问题讨论】:

    标签: protractor


    【解决方案1】:

    以下内容与 async-await 配合得很好:

    public static async clickIfDisplayed(targetElement: ElementFinder) {
        const isPresent = await targetElement.isPresent();
        if (isPresent) {
            const isDisplayed = await targetElement.isDisplayed();
            if (isDisplayed) {
                await PageHelper.click(targetElement);
            }
        }
    }
    

    【讨论】:

    【解决方案2】:
    public static async clickIfDisplayed(targetElement: ElementFinder) {
    
        await targetElement.isPresent().then(bool1 => {
            await targetElement.isDisplayed().then (bool2 => {
                if (bool1 && bool2) {
                    await PageHelper.click(targetElement);
                }
            });
        }
    }
    

    这行得通吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      相关资源
      最近更新 更多