1

因此,对于 Selenium 3.4,我以前工作wait.until的 s 无法正常工作(已被新方法取代)。我似乎无法让新方法发挥作用。

我在用着

import com.google.common.base.Function;

旧代码:

public boolean waitForURLToMatch(String expectedURL, int waitTime){
    WebDriverWait wait = new WebDriverWait(driver, waitTime);
    wait.until(EcpectedConditions.urlMatches(expectedURL));
}

新代码:

public boolean waitForURLToMatch(String expectedURL, int waitTime){
    WebDriverWait wait = new WebDriverWait(driver, waitTime);
    wait.until(new Function<WebDriver, boolean>){

        @Override
        public boolean apply(WebDriver driver) {
            return driver.getCurrentUrl().equals(expectedURL);
        }
    }
}

新代码在eclipse中有错误: Syntax error on tokens, InterfaceHeader expected instead

关于我哪里出错的任何想法?

4

1 回答 1

2

因此,经过大量谷歌搜索后,我最终发现问题只是语法。

这有效:

public boolean waitForURLToMatch(String expectedURL, int waitTime){
    Wait<WebDriver> wait = new WebDriverWait(driver, waitTime);
    Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
        public Boolean apply(WebDriver driver) {
            String currentURL = driver.getCurrentUrl();
            if(currentURL.equals(expectedURL))
            {
                truefalse = true;
                return truefalse;
            }
            truefalse = false;
            return truefalse;
        }
    };
    try{
        wait.until(function);
    } catch (TimeoutException e){   
    }
    return truefalse;
}

编辑:好的,看来这只是一个类路径冲突,现在一切正常,类路径冲突与 Selenium 一起删除了已弃用的 until(predicate) 混淆了这个问题。

于 2017-07-11T01:42:56.637 回答