FluentWait-condition not evaluating to true

I wrote this code based on your example  but the condition never evaluate to true so it keeps on printing “Buzz  Buzz”.

public class FluentWaitCommands {

private static WebDriver driver = null;

public static void main(String[] args) {

driver = new FirefoxDriver();

driver.get(“http://www.toolsqa.com/automation-practice-switch-windows/”);
WebElement element = driver.findElement(By.id(“clock”));

FluentWait<WebElement> wait = new FluentWait<WebElement>(element);

wait.withTimeout(600, TimeUnit.SECONDS);
wait.pollingEvery(500, TimeUnit.MILLISECONDS);
wait.ignoring(NoSuchElementException.class);

Function <WebElement, Boolean> f = new Function <WebElement, Boolean> () {
public Boolean apply (WebElement element) {

if (!element.getText().equals(“Buzz Buzz”))
{
String value = element.getText();
System.out.println(“Value of the element is: ” + value);
return false;
}

System.out.println(“Hurray found Buzz Buzz :D”);
return true;
}

};

wait.until(f);

}
}

Add Comment
  • 4 Answer(s)

    Its working absolutely fine. Try it properly

    Professor Answered on May 11, 2015.
    Add Comment

    This what it shows in the console

    RE: FluentWait-condition not evaluating to true

    Default Answered on May 11, 2015.
    Add Comment

    Well, I am not sure what code you are running here. I copy pasted your code and it works absolutely fine.

    Virender

    Professor Answered on May 12, 2015.
    Add Comment

    Is it possible to solve just by .until and ExpectedConditions class instead of until()’s overloaded method with Function and Predicate? I mean something like this:

    
    public void testTextDisplayed(WebDriver driver){
    
    driver.get("http://toolsqa.com/automation-practice-switch-windows/");
    
    WebElement element = driver.findElement(By.className("timer"));
    WebDriverWait wait = new WebDriverWait(driver, 45);
    
    wait.pollingEvery(100, TimeUnit.MILLISECONDS);
    
    boolean isBuzzBuzz = wait.until(ExpectedConditions.textToBePresentInElementValue(element, "Buzz Buzz"));
    if(isBuzzBuzz){
    
    System.out.println("Buzz Buzz is present!");
    
    }
    
    else{
    
    System.out.println("Buzz Buzz us not present yet.");
    
    }
    }
    
    
    Default Answered on May 17, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.