Search code examples
javaseleniumwebdriverexpected-condition

Waiting until text to be present in element is NOT the string provided


I'm looking for a way to have selenium webdriver wait until the text present in the element location I'm interested is NOT the string provided in the code below.

wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*[@id=\"order-details\"]/div[2]/div/dl/dd[1]/div"),"Completed successfully"));

I'm looking for a way where the "text to be present" is not "Completed successfully" so that the code can move forward and no longer wait


Solution

  • You can try with ExpectedConditions - not

    WebElement element = driver.findElement(By.xpath("//*[@id=\"order-details\"]/div[2]/div/dl/dd[1]/div"));
    wait.until(ExpectedConditions.not(ExpectedConditions.textToBePresentInElement(element, "Completed successfully")));