How to test if an element is present in Selenium

The findElement() method will throw an exception if it fails. To test for the presence of an element without having to catch an exception, use findElements() which returns an empty list if the element isn’t found.

Java

Boolean isPresent = driver.findElements(By.id("myID")).size() > 0;

Python

is_present = driver.find_elements_by_id("myID)

C#

bool IsPresent = driver.FindElements(By.Id("myID")).Count > 0;