How on Selenium Webdriver to check the presence of an element and, if an element is found, then click on it, and if not, then continue with the program?

  • element id is known? - redL1ne
  • Yes, item id is available - Serjik85

1 answer 1

For example:

 boolean present; try { driver.findElement(By.id("")); present = true; } catch (NoSuchElementException e) { present = false; } 

Or:

 if (!driver.findElement(By.id("...")).isEmpty()) { //Click on element } else { //Element was not found }