I tried to write automatic tests for mobile application: "Vinted". I can't make the LoginScreen, because this application has 3 different home screens which loads randomly with different ID for a login button.
I would like you to ask to write a code which: Try to click A. If there is no A it tries to click B. If there is no B then tries to click C.
I tried with:
try {
btn_register1.click();
} catch (NoSuchElementException e) {
btn_register2.click();
btn_register3.click();
}
btn_register 1 and 2 works. But then it comes to a 3 test fails. I want to add that I am very much a beginner with Selenium and JAVA.
What wil happen then btn_register2.click();
throw exception?
You can add one more try-catch block inside catch part, but it's better to do check before you'are clicking on element.
List<WebElement> elements = driver.findElements(By by);
if (elements.size() > 0)
elements.get(0).click();