量角器单击如果显示不起作用使用异步等待 [英] Protractor click if displayed is not working using async await

查看:46
本文介绍了量角器单击如果显示不起作用使用异步等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Protractor click if displayed is not working using async await. I have tried with the following method:

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

即使元素不存在或显示,有时也会点击上面的内容.请帮助理解我在这里出错的地方.

The above sometime clicks even if element is not present or displayed. Please help to understand where I am going wrong here.

推荐答案

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

The following worked well with 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);
        }
    }
}

这篇关于量角器单击如果显示不起作用使用异步等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆