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

Time:07-09

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

CodePudding user response:

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.

CodePudding user response:

WebElement elem = driver.findElement(By.xpath("//button[@id='Edit']"))
Assert.assertEquals(true, elem.isDisplayed()); 

Could just check if it's displayed. Then use Assert.assertNotEquals for the other or just use False.

  • Related