I'm attempting to wait for the WebElement to change from blank,to message 1, then message 2. The problem is I find the first message everytime, but i can't ever seem to wait for the second(it timesout looking for the text)
I've tried having the wait objects separate that didnt work. Ive tried a few of the expected condition methods(textToBePresent*), which after some reading (i found about the refreshed EC) to no avail.
@FindBy(xpath="//p[@class='statusText']")
WebElement statusMsg
public WebElement statusMsg(){
String msg1="Logging in, please wait."
String msg2="Login successful, please wait."
String msg3="Login attempt exception, error code: "
if(statusMsg.getText().contains(msg3)){
log.error(statusMsg.getText())
log.error("Something happened in the frontend")
Assert.fail(statusMsg.getText())
}else{
log.info(statusMsg.getText())
}
WebDriverWait wait = new WebDriverWait(driver,45)
wait.until(ExpectedConditions.textToBe(By.xpath("//p[@class='statusText']"), msg1))
if(statusMsg.getText().contains(msg3)){
log.error(statusMsg.getText())
log.error("Something happened in the backend")
Assert.fail(statusMsg.getText())
}else{
log.info(statusMsg.getText())
}
wait.until(ExpectedConditions.refreshed(ExpectedConditions.textToBe(By.xpath("//p[@class='statusText']"), msg2)))
log.info("Found: "+msg2)
return statusMsg
}
The result is testNG fails my test saying:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for condition (element found by By.xpath: //p[@class='statusText'] to have text "Login successful, please wait.". Current text: "Logging in, please wait.")
Yet I can see the msg2
while the test is running. Does this have to do because I've already initialised the page objects via PageFactory.initElements(driver, this)
?