If statement for clicking on an elememt


#1

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


#2

Anyone able to help with the above?