If statement for clicking on an elememt

Hi,

In one of my tests I have a pop-up that may or may not appear. I’d like to add an if statement to click if it pops up else carry on.

Currently I have got:

MobileElement ok = (MobileElement) driver.findElementsById(“elementhere”);
try {
if (ok.isEnabled()) ;
{
ok.click();
}
} catch (NoSuchElementException ignored) {
}

What this does though is just look for the element and try to click it. If it’s not there then it will fail. I guess I need to add an else statement in but not sure what it should contain.

Thanks

Anyone able to help with the above?

hi
I didn’t get your question exactly? The above code should work perfectly fine. if you are facing an issue with code try to findElement instead of findElements. You can use XPath you can use “finally keyword” if you want some. hope this reply will help you.