我有一个类名为MessageTable的webtable,并且在表数据(td)中有以下列表项
<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 :(得分: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.
}
}
答案 1 :(得分: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());
}