The Type Fluentwait Is Not Generic; It Cannot Be Parameterized with Arguments <Webdriver> Error for Fluentwait Class Through Selenium and Java

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

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

Fluent Wait not working in selenium for angular

I got the another Solution for that. I implemented NgWebDriver's waitForAngularRequestToFinish()

How to use built-in ExpectedConditions with FluentWait?

A bit of background :

Fluent Wait

Fluent Wait is the implementation of the Wait interface which an user can configure its timeout and polling interval on the fly. A FluentWait instance defines the maximum amount of time to wait for a condition along with the frequency with which to check the condition. The user can also configure the wait to ignore specific types of exceptions while waiting, such as NoSuchElementExceptions when searching for an element on the page.

WebDriverWait

WebDriverWait is the tailor-made version of FluentWait that uses WebDriver instances.

You can find a detailed discussion on WebDriverWait and FluentWait in both of these QA Implicit vs Explicit vs Fluent Wait and Differences between impilicit, explicit and fluentwait.

ExpectedConditions

ExpectedConditions are the tailor made canned conditions which are generally useful within webdriver tests.


As per your question, as you are trying with FluentWait since you want to control polling timeout you can still achieve the same through WebDriverWait as follows :

  • WebDriverWait have 3 Constructors and one of them is :

    WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)
  • Details :

    public WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)

    This wait will ignore instances of NotFoundException that are encountered by default in the `until` condition, and immediately propagate all others. You can also add more to the ignore list by calling ignoring(exceptions to add).

    Parameters:
    driver - The WebDriver instance to pass to the expected conditions
    timeOutInSeconds - The timeout in seconds when an expectation is called
    sleepInMillis - The duration in milliseconds to sleep between polls (polling interval).

Solution :

You can use the above mentioned Constructor of WebDriverWait and still can control the polling interval.

Note : To keep your program logic simple and understandable use WebDriverWait instead of Fluent Wait untill and unless absolute necessary.

Trivia :

For further understanding of Fluent Wait you can follow the discussion Selenium Webdriver 3.0.1-[Eclipse-Java-Chrome]: Selenium showing error for FluentWait Class

How to remove deprecation warning on timeout and polling in Selenium Java Client v3.11.0

@Grasshopper 's answer points us to the exact modified constructor of FluentWait and your requirement of removing the deprecation warning from withTimeout and pollingEvery fields. Incase you are facing further difficulty you can use the line of code below :

import java.time.Duration;
//lines of code
Wait<WebDriver> gWait = new FluentWait<WebDriver>(pDriver).withTimeout(Duration.ofSeconds(100))
.pollingEvery(Duration.ofMillis(600)).ignoring(NoSuchElementException.class);

You can find a detailed discussion in The type FluentWait is not generic; it cannot be parameterized with arguments error for FluentWait Class through Selenium and Java



Related Topics



Leave a reply



Submit