简体   繁体   English

硒自动测试中的FluentWait

[英]FluentWait in Selenium automated Testing

I am using the code below, which I got from a StackOverflow answer: 我正在使用下面的代码,该代码是从StackOverflow答案中获取的:

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". Eclipse显示“ 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>(){}) Wait<WebDriver>类型的until(Function<? super WebDriver,T>)不适用于参数(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. 一切似乎都很好,只是您可能对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;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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