Ajay Shinde Ajay Shinde - 1 month ago 11
Java Question

FluentWait throwing "The method unti in the type Wait<WebDriver> is not applicable for the arguments error

I am automating test case. I want to use FluentWait but it is throwing "The method until(Function) in the type Wait is not applicable for the arguments (new Function(){})" error.

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).
withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
wait.until(new Function< WebElement, Boolean >() {
@Override
public Boolean apply(WebElement element) {
return element.getText().contains(employeeFirstName);
}
});


What I am doing wrong here?

Answer
Wait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(60, TimeUnit.SECONDS)
    .pollingEvery(5, TimeUnit.SECONDS)
    .ignoring(NoSuchElementException.class);

wait.until(new Function<WebDriver, Boolean>() {
  @Override
  public Boolean apply(WebDriver driver) {
    return driver.findElement(By.cssSelector("my-css-selector")).getText().contains("name");
  }
});

Worth reading: https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html

Comments