【问题标题】:Effective way to find multiple elements in selenium Test在硒测试中找到多个元素的有效方法
【发布时间】:2016-01-08 13:24:32
【问题描述】:
使用 selenium 测试获取多个名称的最佳做法是什么。考虑我的页面中有以下列,
**ID NAME ADDRESS**
1 Anu Addr1
2 ABU Addr2
3 Raj Addr3
我把名字当作
getWebDriverEx().findUIElement(By.xpath('id of name0')).getTeXT;
如何从上表中获取所有名称?
【问题讨论】:
标签:
java
selenium
automation
【解决方案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();
}
注意:上面的代码我没有编译。