Selenium webdriver 在selenium中,验证页面中存在的元素是否可以接受

Selenium webdriver 在selenium中,验证页面中存在的元素是否可以接受,selenium-webdriver,Selenium Webdriver,我不熟悉硒。。在我的测试脚本中有一个页面,其中有许多文本字段下拉按钮 我必须验证所有字段是否存在于页面中。 我是这样做的: if(webElement.isDisplayed()){ Reporter.log("abc displayed "); } else { Reporter.log("abc failed to display"); Assert.fail(); } 否,webElement.isDisplayed()用于

我不熟悉硒。。在我的测试脚本中有一个页面,其中有许多文本字段下拉按钮

我必须验证所有字段是否存在于页面中。 我是这样做的:

if(webElement.isDisplayed()){ 
   Reporter.log("abc displayed ");      
} else {                
   Reporter.log("abc failed to display");
   Assert.fail();
}

否,
webElement.isDisplayed()
用于判断元素是否显示,如果要验证它是否存在,请使用以下命令:

public WebElement untilAdded(By by) {
        return new FluentWait<SearchContext>(context)
                .withTimeout(timeout, timeUnit)
                .pollingEvery(interval, TimeUnit.MILLISECONDS)
                .ignoring(NoSuchElementException.class)
                .until(new Function<SearchContext, WebElement>() {
                    public WebElement apply(SearchContext context) {
                        return context.findElement(by);
                    }
                });
    }
未添加的公共WebElement(按){
返回新FluentWait(上下文)
.withTimeout(超时,时间单位)
.pollingEvery(间隔、时间单位.毫秒)
.忽略(NoSuchElementException.class)
.until(新函数(){
公共WebElement应用(搜索上下文){
返回context.findElement(按);
}
});
}

否,
webElement.isDisplayed()
用于判断元素是否显示,如果要验证元素是否存在,请使用以下命令:

public WebElement untilAdded(By by) {
        return new FluentWait<SearchContext>(context)
                .withTimeout(timeout, timeUnit)
                .pollingEvery(interval, TimeUnit.MILLISECONDS)
                .ignoring(NoSuchElementException.class)
                .until(new Function<SearchContext, WebElement>() {
                    public WebElement apply(SearchContext context) {
                        return context.findElement(by);
                    }
                });
    }
未添加的公共WebElement(按){
返回新FluentWait(上下文)
.withTimeout(超时,时间单位)
.pollingEvery(间隔、时间单位.毫秒)
.忽略(NoSuchElementException.class)
.until(新函数(){
公共WebElement应用(搜索上下文){
返回context.findElement(按);
}
});
}

使用WebDriverWait等待元素出现

(new WebDriverWait(driver, 30)).until(ExpectedConditions.presenceOfElementLocated(By by));

对于其他预期条件,请阅读API中的零件,使用WebDriverWait等待元素出现

(new WebDriverWait(driver, 30)).until(ExpectedConditions.presenceOfElementLocated(By by));

对于其他预期条件,请阅读API中的零件

不要使用isdisplayed方法检查元素是否存在。如果元素不存在,U将获得异常。使用findelements方法并检查列表的大小。不要使用isdisplayed方法检查元素是否存在。如果元素不存在,U将获得异常。使用findelements方法并检查列表的大小。