1

Below is my element;

String sId = driver.findElement(By.xpath(path)).getAttribute("data-id");

Since now the attribute value is stored in "sId", I now need to tell Selenium to wait until data-id attribute value is NOT equal to sID. I have tried the code below with no luck:

wait.until_not(ExpectedConditions.textToBePresentInElement(By.xpath(path), sId));

I get the error:

The method until_not(ExpectedCondition) is undefined for the type WebDriverWait

Also even if I change "until_not" to "until" I get this warning:

The method textToBePresentInElement(By, String) from the type ExpectedConditions is deprecated

How do I do it?

1
  • To wait until data-id attribute value is NOT equal to sID will be False-Possitive. IMO, if usecase permits, you should wait for value is equal to sID Sep 25, 2018 at 5:58

3 Answers 3

2

If you are checking the attribute value checking the text won't help you, those are two different things.

You can combine the not and attributeToBe ExpectedConditions for that

wait.until(ExpectedConditions.not(ExpectedConditions.attributeToBe(By.xpath(path), "data-id", sId)));
1

You can try to use not from Expected conditions, for example:

wait.until(ExpectedConditions.not(ExpectedConditions.textToBePresentInElement(<element>, <elementtext>)));

Or you can also use expected conditions invisibility method:

wait.until(ExpectedConditions.invisibilityOfElementWithText(locator, text));
0

You can try bellow code

String sId = driver.findElement(By.xpath(path)).getAttribute("data-id");        

boolean expectedCondition = false;
boolean timeOut = false;
int second = 1;
do {
    try {
        //timeout for 60 seconds
        if(second>60) {
            timeOut = true;
        }
        String expectedId = driver.findElement(By.xpath(path)).getAttribute("data-id");
        if(! expectedId.equals(sId)) {
            expectedCondition=true;
        }else {
            second++;
        }
    } catch (Exception e) {
        TimeUnit.SECONDS.sleep(1);
        second++;
    }
}while(expectedCondition==false && timeOut==false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.