I'm trying to run a if - else loop for two conditions. the code checks the if condition and tries to find that but if it fails it doesn't execute the else code.
if (driver.findElement(AppiumBy.accessibilityId("___")).isDisplayed())
{
driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"OK\"]")).click();
driver.findElement(AppiumBy.xpath("//XCUIElementTypeButton[@name=\"menu_edit\"]")).click();
driver.findElement(AppiumBy.accessibilityId("Locations")).click();
driver.findElement(AppiumBy.accessibilityId("0")).click();
deleteLocation();
driver.findElement(AppiumBy.accessibilityId("cancel_dm")).click();
driver.findElement(AppiumBy.accessibilityId("userProfile")).click();
driver.findElement(AppiumBy.xpath("//XCUIElementTypeButton[@name=\"Delete Account\"]")).click();
driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"YES\"]")).click();
Thread.sleep(3000);
driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"OK\"]")).click();
}
else {
driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name=\"OK\"]")).click();
}
Here the code never executes the else block and gets stuck at the if condition even when it is unable to locate that element