Sobes.tech
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 findElements method returns an empty list).
  • Check that the element exists in the DOM, but its CSS property display is set to none, or visibility is hidden, or the element is outside the visible area.
  • Use framework methods, for example, in Selenium, isDisplayed() returns false if 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.

How to check that an element is not displayed on the… - sobes.tech