【问题标题】:FluentWait function cannot be used in function of Java ClassFluentWait 函数不能在 Java 类的函数中使用
【发布时间】:2013-12-05 04:29:19
【问题描述】:

这可能是一个基本问题,但我对 Java 和 Selenium Webdriver 不太熟悉。我不知道为什么 Eclipse 显示错误以将 'Function' 更改为 Eclipse 的'删除类型参数'。我想在课堂上使用 fluentwait 作为函数。或者正确的使用方法是什么?

public class Process()
   {
    public void Start()
    {
        //function call
        WebElement index = fluentWait(By.xpath("xxx"), driver);
    }   

    //function method
    public WebElement fluentWait(final By locator, WebDriver driver) {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(30, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

        WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
            public WebElement apply(WebDriver driver) {
                return driver.findElement(locator);
            }
        });

        return  foo;
    };
   }

【问题讨论】:

  • 我无法在本地重现该问题,也许您可​​以添加要导入的 WaitFunction 类?顺便说一句,我必须删除 Process 之后的括号 - 它是一个类,而不是一个函数。
  • @blalasaadri 您的建议可能是我在 Java 项目中所缺少的。我导入为:import org.openqa.selenium.support.ui.FluentWait;导入 org.openqa.selenium.support.ui.Wait;导入 org.openqa.selenium.support.ui.WebDriverWait;但是如何导入“功能”?
  • 那么您可能希望在您的导入中使用import com.google.common.base.Function;

标签: java eclipse selenium


【解决方案1】:

您似乎未能导入com.google.common.base.Function

【讨论】:

    猜你喜欢
    • 2017-07-05
    • 2016-09-02
    • 2014-01-19
    • 2019-06-30
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多