if else statement not working in testcafe

283 views Asked by At
async selectLocalAdmin(){
    if(this.localAdmin.visible){
         await t.click(this.localAdmin);
    }
    else{
         console.log('not visible');
    }

}

I was trying to add some if else statements here and i observe that even when the if statment is true the click function is not happening, any idea on why this is happening?

1

There are 1 answers

0
vasily.strelyaev On

Without a complete sample, I can only say that the selector.visible property returns a promise (assuming localAdmin is a Selector), so you need to add await:

async selectLocalAdmin() {
    if (await this.localAdmin.visible) {
         await t.click(this.localAdmin);
    }
    else{
         console.log('not visible');
    }
}

If this does not fix the issue, please share the complete test code (include the URL of the tested application, which should be publicly accessible).