WebDriver: check if an element exists? [duplicate]

How to check if an element exist with web driver?

Is using a try catch really the only possible way?

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

10 Answers
10

Leave a Comment