Middle
How to check that an element is not displayed on the page?
sobes.tech AI
Answer from AI
To verify that an element is not displayed on a page, several approaches can be used in automated testing:
- Check that the element is absent in the DOM (for example, the
findElementsmethod returns an empty list). - Check that the element exists in the DOM, but its CSS property
displayis set tonone, orvisibilityishidden, or the element is outside the visible area. - Use framework methods, for example, in Selenium,
isDisplayed()returnsfalseif the element is hidden.
Example in Selenium (Java):
List<WebElement> elements = driver.findElements(By.id("elementId"));
if (elements.isEmpty() || !elements.get(0).isDisplayed()) {
System.out.println("The element is not displayed on the page");
}
Thus, it is important to clarify what exactly "not displayed" means: whether the element is absent in the DOM or it is hidden by styles.