How do you check if an element is present in Selenium?
The most straightforward way to do this is by using the findElement() method. This method will return a WebElement object if the element is found, or it will return null if it is not. Given below is an example:
WebElement element = driver.findElement(By.id(“email”));
if (element != null) {
There are also some other ways of checking for the presence of an element, and these methods may sometimes prove useful in different situations. One such alternative is the contains() method, which will return true if the element you’re searching for is within the bounds of the current element, and false otherwise.
Know more: Verifying whether an element present or visible in Selenium Webdriver