the method withtimeout(duration) in the type fluentwait<webdriver> is not applicable for the arguments (int, timeunit)

5.9k Views Asked by At

An error appear while working with this code the error is

"The method withTimeout(Duration) in the type FluentWait is not applicable for the arguments (int, TimeUnit)"

Wait wait = new FluentWait(driver)    
    .withTimeout(30, SECONDS)    
    .pollingEvery(5, SECONDS)   
    .ignoring(NoSuchElementException.class);
3

There are 3 best solutions below

1
Arun Nair On BEST ANSWER

This is the correct usage now..

Wait wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30))
                    .ignoring(NoSuchElementException.class);
1
Mohamed Elgamal On

I searched and the following code worked for me

            Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(10, TimeUnit.SECONDS)
                .pollingEvery(2, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);
0
Kapil Sharma On

Following work with one condition, variable name should be anything instead of "wait" , i.e. "wait1" would work

#CompleteWaitCode

@SuppressWarnings("unchecked")
Wait **wait1** = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30)).ignoring(NoSuchElementException.class);
        
@SuppressWarnings("unchecked")
WebElement element = (WebElement) wait1.until(new Function<WebDriver, WebElement>() {
           
public WebElement apply(WebDriver arg0) {
WebElement linkelement = driver.findElement(By.cssSelector("button[class='btn btn-primary']"));

if (linkelement.isEnabled()) {
      System.out.println("Element is Found");
                }
 return linkelement;
      }
});