When is the first call in pollingEvery() method?

186 Views Asked by At

I'm working on Selenium now and I have to use FluentWait. There's a line in my code which led me straight here.

    .pollingEvery(Duration.ofMillis(250))

When is the first call? Is it at the moment I run the code or after 250 millis?

I've been looking for the answear but all I got was that Selenium checks if the WebElement is visible every 250 millis (in this case).

FluentWait <WebDriver> fluentWait = new FluentWait <> (driver);
WebElement myWorldMessage = fluentWait
.withTimeout(Duration.ofSeconds(5))
.pollingEvery(Duration.ofMillis(250))
.ignoring(NoSuchElementException.class)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='finish']/h4")));
1

There are 1 best solutions below

0
On BEST ANSWER

It checks immediately and then polls (checks again) every 250ms.

You might check into WebDriverWait and ExpectedConditions. WebDriverWait extends FluentWait but uses some defaults and is easier to set up. Your code would turn into

new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='finish']/h4")));

See the sources.