In this section, we are going to look at some tips and tricks that might be of use when trying to find elements on the page. We can also apply them to see if the elements are not on the page.
Selenium WebDriver is really good at letting you know when an element does not exist. If it throws a
NoSuchElementException, then we know it's not there. Unfortunately I, and many others, have not been big fans of using exception handling as a way of flow control.
To get around this we can use the
findElements() call, and then we just need to check that the size of the list returned is 0. For example:
List<WebElement> elements = driver.findElements(By.Id("myElement")); elements.size(); //This ...