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

With the availability of Selenium v3.11.0 the constructor of FluentWait have changed. Now the argument type for withTimeout and pollingEvery is Duration. Here is the modified implementation :

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

import com.google.common.base.Function;

public class Fluent_Wait {

    public static void main(String[] args) {


        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
            driver.get("https://www.google.com");
            // Waiting 30 seconds for an element to be present on the page, checking
            // for its presence once every 500 milliseconds.
            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"));
            }
        });

    }

}

Leave a Comment