2016-11-30 17 views
1

我是新來的硒..在我的測試腳本有一個頁面有很多文本字段下拉按鈕。在硒是可以接受的驗證ellements目前在一個頁面

我必須驗證所有該字段是否存在於頁面中或否。 我做這樣的:

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

不要使用isdisplayed方法來檢查,如果元素存在於閱讀ExpectedConditions部分。如果元素不存在,U會得到一個異常。使用findelements方法並檢查列表的大小。 – Grasshopper

回答

0

NO,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); 
        } 
       }); 
    } 
0

使用WebDriverWait等待外觀的元素。

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

其他ExpectedConditions的API

相關問題