How can I check if an element exists with Selenium WebDriver? [duplicate]

You could alternatively do:

driver.findElements(By.id("...")).size() != 0

Which saves the nasty try/catch

P.S.:

Or more precisely by @JanHrcek here

!driver.findElements(By.id("...")).isEmpty()

Leave a Comment