How to perform ele.click() on the condition when ele.isdieplayed=true

Viewed 24

I am trying to click one button when we have one banner displaying on window for that have below code written

  async userAcceptCookie()
{
    if(cplLanding.cookieBanner.isDisplayed()==true)
    {

        log.console("true")
        await cplLanding.cookieBanner.click()
    }
}
}

however the code is not working, can anyone share with me the correct approach here.

1 Answers

By checking the existence of your banner with querySelector, your if condition will run, otherwise null will be returned.

if (document.querySelector("#cookieBanner")) {
  document.querySelector("#btn").addEventListener("click", () => {
    console.log("Hello");
  });
}
Related