2016-04-29 209 views
0

考虑我有一个网表与类名的消息表和具有表里面的数据下面的列表项(TD)如何从selenium webdriver中的表数据获取列表项值?

<td> 
<ul class="error"> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation1</li> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation2</li> 
<li class="ng-binding ng-scope" ng-repeat="error in errors">Validation3</li> 
</ul> 
</td> 

我需要阅读从网络上述所有内容(Validation1,Validation2,Validation3)页面,并需要根据预期的验证消息进行验证。

你能帮我解决这个情况吗?

+0

为什么不创建一个列表''收集,然后通过它旋转? – Brian

+0

哪种语言? –

+0

谢谢Brian。我已经使用列表集合,它正在工作很好实现我的方案WebElement table = driver.findElement(By.className(“messageTable”)); 列表 rows = table.findElements(By.tagName(“li”)); \t \t \t \t \t \t \t \t 为(WebElement元件:行){ \t \t \t \t \t \t \t的System.out.println(element.getText()); \t \t} – Subburaj

回答

1

我认为class="ng-binding ng-scope" ng-repeat="error in errors"只出现在您的表中。
试试这个:

List<WebElement> elems= driver.findElements(By.cssSelector("li.ng-binding.ng-scope[ng-repeat$='errors']")); 

for(WebElement element:elems){ 
    if(element.getText().equals("ur validation message")){ 
     //do something as ur wish. 
    } 
} 
+0

谢谢noor。我已经使用了下面的步骤,它工作正常。 for(WebElement element:rows){System.out.println(element.getText()); } – Subburaj

0

我已经找到了上述问题的解决方案。请找工作步骤

WebElement table = driver.findElement(By.className("messageTable")); 
    List<WebElement> rows = table.findElements(By.tagName("li")); 

     for(WebElement element:rows){ 

      System.out.println(element.getText()); 

    } 
相关问题