In real-time automation, do we check for the presence of every element(in test) before performing some action on them?
Wherever there is a findElement
You may find the use of the class AbstractWebDriverEventListener particularly useful. This class implements the interface WebDriverEventListener which defines before and after hooks for the events triggered by WebDriver.
One such before hook beforeFindBy could be implemented to check the presence of element. For example:
public void beforeFindBy(By by, WebElement element, WebDriver driver) {
// Explicit wait to check for the presence of the element using the "by" locator
}
Similarly the before hook beforeClickOn could be implemented to check that the element is clickable before the click event is performed on that element.