Search code examples
javaseleniumselenium-webdriverassertion

How to write Assert condition to check a particular element is not displayed for dummy users?


By.xpath("//button[@id='Edit']")
  • This particular Edit button should be displayed for Admin users
  • If we login with a different user, we are not showing them the Edit Button
  • How to write Assert condition to verify Edit button is not displayed for other users

Solution

  • I will search for all elements with this XPath and put them in List:

    List<WebElement> elements = driver.findElements(By.Xpath("//button[@id='Edit']"));
    

    Then I will check if the count (size) of the elements in the list is zero, this will mean that the element was not found.