简体   繁体   中英

FluentWait in Selenium automated Testing

I am using the code below, which I got from a StackOverflow answer:

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

wait.until(new Function<WebDriver, Boolean>() {
    @Override
    public Boolean apply(WebDriver driver) {
        return driver.findElement(By.cssSelector("my-css-selector")).getText().contains("name");
    }
});

Eclipse is showing an error on "until". When I hover the mouse on it it says:

The method until(Function<? super WebDriver,T>) in the type Wait<WebDriver> is not applicable for the arguments (new Function<WebDriver,Boolean>(){})

What am i missing?

Everything seems to be fine, Its just that you might have used the wrong import for Function.

You may want to go with:-

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

wait.until(new com.google.common.base.Function<WebDriver, Boolean>() {
    @Override
    public Boolean apply(WebDriver driver) {
        return null;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM