我使用流利的等待,但我不知道为什么我的功能错误

时间:2014-09-23 14:29:43

标签: selenium

我想在我的代码中使用流畅的等待,但我在Function(Function<Boolean> f = new Function<Boolean>())行上收到错误。

FluentWait<WebElement> wait = new FluentWait<WebElement>(verificationtxt);

wait.withTimeout(600, TimeUnit.SECONDS);

wait.pollingEvery(5, TimeUnit.SECONDS);

wait.ignoring(NoSuchElementException.class);

Function<Boolean> f = new Function<Boolean>()
        {
    public Boolean apply(WebElement verificationtxt)
    {
        if(verificationtxt.getText().length()>0)
        {
            return true;
        }
        return false;
    }
        };
wait.until(f);

1 个答案:

答案 0 :(得分:0)

这一行应该是:

Function<WebElement, Boolean> f = new Function<WebElement, Boolean>()

完整源代码:

包裹测试;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.FluentWait;

导入com.google.common.base.Function;

公共类FluentWaitTest {

public void fluentWaitDemo() {
    WebDriver driver = new FirefoxDriver();

    WebElement verificationtxt = driver.findElement(By.name("verificationtxt"));

    FluentWait<WebElement> wait = new FluentWait<WebElement>(verificationtxt);

    wait.withTimeout(600, TimeUnit.SECONDS);

    wait.pollingEvery(5, TimeUnit.SECONDS);

    wait.ignoring(NoSuchElementException.class);

    Function<WebElement, Boolean> f = new Function<WebElement, Boolean>() {
        public Boolean apply(WebElement verificationtxt) {
            if (verificationtxt.getText().length() > 0) {
                return true;
            }
            return false;
        }
    };
    wait.until(f);
}

}