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

fluentwait- selenium easy
fluent wait withtimeout deprecated
fluent wait in selenium python
fluent wait syntax
method until in class fluentwait<t cannot be applied to given types
fluent wait not working
which of the following exceptions is not ideal to be handled(ignore) via fluentwait
fluent wait vs implicit wait

I am working with Selenium Standalone Server 3.0.1. I am trying to add an Explicit Wait to my code to detect an element through xpath when the element becomes visible. In order to get some Java help I looked out for the source code for Selenium Standalone Server 3.0.1 but was unable to find it. I found the source code in selenium-java-2.53.1 release. I downloaded it and found selenium-java-2.53.1-srcs and added to my Eclipse IDE. From the help of FluentWait, I simply copy pasted the code in my Eclipse IDE and changed the variable names.

The sample code in documentation is like:

   // Waiting 30 seconds for an element to be present on the page, checking
   // for its presence once every 5 seconds.
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

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

But when I implement this code, simply copy pasting it:

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

       WebElement element = wait.until(new Function<WebDriver, WebElement>()        {
         public WebElement apply(WebDriver driver) {
           return driver.findElement(By.xpath("//p[text()='WebDriver']"));
         }
       });

I am getting an error on FluentWait Class as The type FluentWait is not generic; it cannot be parameterized with arguments <WebDriver>

Here is the list of my imports:

    import java.util.concurrent.TimeUnit;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    import org.openqa.selenium.By;
    import org.openqa.selenium.NoSuchElementException;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.Wait;
    import com.google.common.base.Function;

Can anyone help me out please?


Update

Added an answer with respect to the modified constructor of FluentWait in Selenium v3.11.0

You need to specify expected condition inside the wait below is the modified code that could solve your problem.

Code:

import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

public class DummyClass
{
    WebDriver driver;
    @Test
    public void test()
    {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(30, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);

        until(new Function<WebElement, Boolean>() 
        {
            public Boolean apply(WebElement element)
            {
                return element.getText().endsWith("04");
            }

            private void until(Function<WebElement, Boolean> function)
            {
                driver.findElement(By.linkText("Sample Post2"));
            }
        }
    }
}

Error for FluentWait: "The type FluentWait is not generic; it cannot be , The type FluentWait is not generic; it cannot be parameterized with arguments <​WebDriver> error for FluentWait Class through Selenium and  “The type FluentWait is not generic; it cannot be parameterized with arguments 1 quick fix available – remove type arguments”. Can u help with this please.

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"));
            }
        });

    }

}

The type List is not generic; it cannot be parameterized with arguments, In Java, the java.util and java.awt packages both define a type called List . The util version is the collections interface that is commonly used. – The type FluentWait is not generic; it cannot be parameterized with arguments 2.The import org.openqa.selenium.support.ui.FluentWait conflicts with a type defined in the same file I have copy pasted the above code and using Selenium 3.But still getting above mentioned errors

The simplest solution is to use the other method implementation:

withTimeout(Duration.ofSeconds(10))
            .pollingEvery(Duration.ofSeconds(2))

The form withTimeout(Duration timeOut) is still used and non-deprecated one

Selenium FluentWait, Selenium FluentWait can define the maximum amount of time to wait for a FluentWait uses two parameters mainly – timeout value and polling frequency. “The type FluentWait is not generic; it cannot be parameterized with  Function interface is a generic interface, and it is represented as Function<T, R> where T is the type of object passed to apply method and R is the type of object returned by the apply function. If we are implementing the Function interface, we must provide an implementation for the abstract apply() method present in the Function Interface.

The type FluentWait is not generic; it cannot be parameterized with , The type FluentWait is not generic; it cannot be parameterized with arguments <​WebDriver> error for FluentWait Class through Selenium and  Also, you must note that without importing the <com.google.common.base.Function> package, your Fluent Wait code may not compile instead will throw errors. 3.2- User Case Scenario and the HTML Code to Run Fluent Wait Command Sample. Let’s now review the use case which we want to automate. There is a simple button on the web page.

What is FluentWait in Selenium WebDriver and How to implement, The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java. Fluent wait: Fluent wait is another type of Explicit wait and you can define polling and ignore the exception to continue with script execution in case element is not found. new FluentWait<WebDriver>(driver).withTimeout(30, TimeUnit.SECONDS).pollingevery(10, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);

Solved: The type list is not generic; it cannot be parameterized with , Fluentwait in selenium webdriver is one of the important waits in Selenium. public static void main(String[] args) throws InterruptedException { The type FluentWait is not generic; it cannot be parameterized with arguments. Note that not all open constructed types are generic. For example, an array whose element type is a generic type definition is not generic, and a pointer to an open constructed type is not generic. closed constructed type: The ContainsGenericParameters property is false. When examined recursively, the type has no unassigned generic parameters.

Comments
  • Did you try the example out of the docs? seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/…
  • @JeffC Thanks. I can see some difference between the documentation provided by selenium-java-2.53.1 src code and the documentation provided in the URL you shared. While in selenium-java-2.53.1 src code the creating an object is <<-- Wait<WebDriver> wait = new FluentWait<WebDriver>(driver) -->> but the link documentation says it as <<-- Wait wait = new FluentWait(driver) -->>
  • I have edited the code or check below code if it could help? FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) .withTimeout(100, TimeUnit.SECONDS) .pollingEvery(50, TimeUnit.MILLISECONDS); // start waiting for given element wait.until(new ElementWaitCondition(browser, query));
  • Thanks, if I provide, << FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)>> Eclipse IDE is still showing me error as The type FluentWait is not generic; it cannot be parameterized with arguments <WebDriver>
  • I am able to implement without any error, i am using Selenium-java 3.0.1 and server 3.0.1
  • Thanks Sir. To update you, as of now I have added the following import import org.openqa.selenium.support.ui.Wait; if I try to import import org.openqa.selenium.support.ui.FluentWait; Eclipse IDE shows me an error as "The import org.openqa.selenium.support.ui.FluentWait conflicts with a type defined in the same file". Any other suggestions please?
  • I did two changes, First I deleted my class file "FluentWait.class" which I suspect was referring to the interface. Created a new class file "FluentWaitExample" and I have added both the imports import org.openqa.selenium.support.ui.FluentWait; and import org.openqa.selenium.support.ui.Wait; Still I get an error at << new FluentWait<WebDriver>(driver) >> The error says FluentWait cannot be resolved to a type
  • Thanks DebanjanB, it eliminated message: " Warning:() java: withTimeout(long,java.util.concurrent.TimeUnit) in org.openqa.selenium.support.ui.FluentWait has been deprecated"