0

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);
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66

3 Answers3

2

This is the correct usage now..

Wait wait = new FluentWait(driver).withTimeout(Duration.ofSeconds(30)).pollingEvery(Duration.ofSeconds(30))
                    .ignoring(NoSuchElementException.class);
Arun Nair
  • 425
  • 3
  • 11
  • Just to be clear considering various Selenium versions in use, as you can see in the javadocs, https://www.javadoc.io/doc/org.seleniumhq.selenium/selenium-support/3.141.59/org/openqa/selenium/support/ui/FluentWait.html, changing the parameter type for the method `withTimeout()` to `java.time.Duration` hadn't been done yet in the 3.141.59 release version, which was current when you posted this. This change wasn't added until selenium 4, which was at 4.0 Alpha 3 at the same time. – MiB Dec 20 '22 at 15:14
0

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);
  • At least now in Selenium 4, `withTimeout()` takes a single `java.time.Duration` parameter and won't accept the code above. So would be `Wait wait = new FluentWait(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class);` It seems in version 3 your code did indeed work. – MiB Dec 20 '22 at 14:58
0

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