FluentWait throw&#34;直到Wait <webdriver>类型的方法不适用于参数&#34;错误

时间:2015-12-09 10:25:57

标签: java selenium

我正在自动化测试用例。我想使用FluentWait,但它正在抛出&#34;等待类型Wait中的(Function)方法不适用于参数(new Function(){})&#34;错误。

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).
                withTimeout(60, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);
               wait.until(new Function< WebElement, Boolean >() {
            @Override
            public Boolean apply(WebElement element) {
                return element.getText().contains(employeeFirstName);
            }
        });

我在这里做错了什么?

4 个答案:

答案 0 :(得分:2)

添加此

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>21.0</version>
</dependency>

答案 1 :(得分:0)

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

答案 2 :(得分:0)

我尝试了WebDriverWait而不是FluentWait,这对我有用。

WebDriverWait wait = new WebDriverWait(Driver, 60);
wait.withTimeout(60, TimeUnit.SECONDS);
wait.pollingEvery(5, TimeUnit.SECONDS);
wait.ignoring(NoSuchElementException.class);
wait.until(new ExpectedCondition<Boolean>(){
    @Override
    public Boolean apply(WebDriver driver) {
        WebElement ele=driver.findElement(locator);
        if(ele==null)
            return false;
        else
        {
            System.out.println("found");
            return true;
        }     
    }
});

答案 3 :(得分:0)

最简单的解决方案是使用其他方法实现:

withTimeout(Duration.ofSeconds(10))
            .pollingEvery(Duration.ofSeconds(2))

表格withTimeout(Duration timeOut) 仍在使用且不推荐使用