2016-01-08 66 views
-1

使用硒測試獲取多個名稱的最佳做法是什麼?想想我有以下列在我的網頁,在硒中查找多個元素的有效方法測試

**ID NAME ADDRESS** 

1 Anu Addr1 
2 ABU Addr2 
3 Raj Addr3 

我已經採取了第一個名字爲

getWebDriverEx().findUIElement(By.xpath('id of name0')).getTeXT; 

我如何從上面的表中的所有的名字嗎?

回答

1

你可以試試下面的代碼,

WebElement table=driver.findElement(By.id("tableid")); 
List<WebElement> rows=table.findElements(By.xpath("tr")); 
for(int i=0;i<rows.size();i++){ 
    String name=rows.get(i).findElements(By.xpath("tr/td")).get(1).getText(); 
} 

注:我沒有上面的代碼編譯。