How to wait until the innertext of an element is changed

Hello,
issue1: I want to wait for my script until the inner text of a given element has changed after an action. I tried the following scripts but it is not working. But it’s not waiting for the text to be changed.

pageObject variables

String pageNavigated = “//div[@id = ‘gatsby-announcer’]”
CustomKeywords.‘ciautils.ciaUtilities.addGlobalVariable’(‘pageNavigated’, pageNavigated)

String pageNavigatedText =""
CustomKeywords.‘ciautils.ciaUtilities.addGlobalVariable’(‘pageNavigatedText’, pageNavigatedText)

Test script in test case

String text= “”
CustomKeywords.‘ciautils.ciaUtilities.navigateToPage’(GlobalVariable.careerButton)
boolean testResult = new ciaUtilities().waitVerifyPageNavigated(By.xpath(GlobalVariable.pageNavigated), text, 5)

CustomKeyword class

def static boolean waitVerifyPageNavigated(By locator, String checkText, int timeout){
WebDriverWait wait = new WebDriverWait(driver, timeout);
boolean boolValue
try{
if (wait.until(ExpectedConditions.not(ExpectedConditions.textToBePresentInElementValue(locator, checkText)))) // here with the locator it gets some text and when compared with “” it is not waiting till it turned to “”
{
String text= driver.findElement(By.xpath(GlobalVariable.pageNavigated)).getText()
println(text)
GlobalVariable.pageNavigatedText == text
boolValue = true
}
}catch(e){
println(e)
boolValue =false
}
return boolValue
}

@vtanguturi

Have you tried this solution ?

String expectedValue = "abcd";
String actualValue = driver.findElement(By.xpath("your xpath")).getText().toLowerCase()

wait.until(ExpectedConditions.textToBePresentInElement(By.xpath("path"), actualValue));

Source:

Yeah, I tried the same after posting this question. But that example was to wait till the text is present but what I want is wait till the text is not present. So I added expectedConditions.not. But still it didn’t work as how I need. so at last I came up with a solution to use while loop and now it worked perfectly as how I need.
Thanks though for your reply

1 Like