0
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
    .withTimeout(Duration.ofSeconds(30))
    .pollingEvery(Duration.ofMillis(500))
    .ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
    public WebElement apply(WebDriver driver) {
        return driver.findElement(By.name("q"));
    }
});

Tried to work on Fluent wait implementation with Selenium 3.141.59 but getting the specified compile time error. I am mainly concerned with "new Function method"

The type FluentWait is not generic; it cannot be parameterized with arguments <WebDriver> error for FluentWait Class through Selenium and Java

I don't believe this is a duplicate. Question may sound the same but none of the solutions worked for me.

Error Shown:

The type Function is not generic; it cannot be parameterized with arguments <WebDriver, WebElement>
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • Perhaps you are not importing the correct Function interface (or another interface/class of the same name are hiding it). – Eran May 29 '19 at 11:48

1 Answers1

1

What are you actually trying to do with this explicit wait?

You could use a pre-defined Expected Condition:

wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));

The reason you are having problems is that you are trying to create a new instance of a Function which is an interface, you can't do that. You could refactor the above ExpectedCondition into:

wait.until(new ExpectedCondition<WebElement>() {
    @Override
    public WebElement apply(WebDriver driver) {
        return driver.findElement(By.name("q"));
    }
});

It looks quite close to your attempt, but it's not very readable or reusable. I would suggest that you create your own helper class with your own expected conditions in that looks like the standard ExpectedConditions class supplied by Selenium.

Ardesco
  • 7,281
  • 26
  • 49