WaitForTextNotPresent with Webdriver Java

302 Views Asked by At

I have tried to implement something then wait until a special text not more displayed on the webpage.

My solution for waitForTextPresent works fine:

driver.findElement(By.tagName("body")).getText().contains("text");

But I search the solution to negate it, please help me.

3

There are 3 best solutions below

0
On

I usually use the invisibilityOfElementLocated, like this:

new WebDriverWait(driver, EXPLICIT_TIMEOUT).ignoring(NoSuchElementException.class)
            .until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(xpath)));
3
On

.contains() returns a boolean, so negate it as usual !driver.findElement(By.tagName("body")).getText().contains("text");

0
On

Simply use ! operator

WebElement element= driver.findElement(By.tagName("body"));
 if(!element.getText().contains("text to match"))
  {
  //code......
  }