Im trying the code below but it seems it does not work... Can someone show me the best way to do this?
public void verifyThatCommentDeleted(final String text
Instead of doing findElement, do findElements and check the length of the returned elements is 0. This is how I'm doing using WebdriverJS and I expect the same will work in Java
WebElement element = driver.findElement(locator);
Assert.assertFalse(element.isDisplayed());
The assertion will pass if the element is not present, otherwise it will fail.
Use findElements instead of findElement.
findElements will return an empty list if no matching elements are found instead of an exception. Also, we can make sure that the element is present or not.
Ex: List elements = driver.findElements(By.yourlocatorstrategy);
if(elements.size()>0){
do this..
} else {
do that..
}
In Python for assertion I use:
assert len(driver.find_elements_by_css_selector("your_css_selector")) == 0
int i=1;
while (true) {
WebElementdisplay=driver.findElement(By.id("__bar"+i+"-btnGo"));
System.out.println(display);
if (display.isDisplayed()==true)
{
System.out.println("inside if statement"+i);
driver.findElement(By.id("__bar"+i+"-btnGo")).click();
break;
}
else
{
System.out.println("inside else statement"+ i);
i=i+1;
}
}
WebElement element = driver.findElement(locator);
Assert.assertNull(element);
The above assertion will pass if element is not present.