Aarushi Garg
Aarushi Garg

Reputation: 1

if else statement not working in testcafe

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?

Upvotes: 0

Views: 326

Answers (1)

vasily.strelyaev
vasily.strelyaev

Reputation: 838

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).

Upvotes: 2

Related Questions