代码:

public WebElement findElement(By by){
    if (!waitEle(by)){
        throw new RuntimeException("cannot find ele : " + by);
    }
    return webElement.findElement(by);
}
private Boolean waitEle(By by) {
    if (by == null){
        return false;
    }
    WebDriverWait wait = new WebDriverWait(driver, waitTimeDefault);
    try {
        wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(by));
    } catch (Exception e) {
        return false;
    }
    return true;
}

报错如下:

我先等待元素存在再去查找元素,为何还是找不到该元素


↙↙↙阅读原文可查看相关链接,并与作者交流