【发布时间】:2016-03-21 10:47:14
【问题描述】:
如何从没有名称或 xpath 的复选框列表中获取选定的复选框
复选框图片enter image description here
生成的 HTML 代码
<div class="checkbox ng-scope" ng-repeat="item in options track by $index">
<label class="ng-binding" style="float:left;">
<input type="checkbox" class="ng-pristine ng-valid" ng-change="textfieldKeypress(onkeypress)" ng-model="$parent.inputArray[$index]" validator="[onwatch,onblur]" value="item" >
Ache </label>
</div>
这是我尝试过但不是正确的方法,因为有多个没有名称的复选框列表
List<WebElement> CheckBoxList = driver.findElements(By.tagName("checkbox"));
for (int i = 0; i < CheckBoxList.size(); i++) {
if (CheckBoxList.get(i).isSelected()) {
Assert.assertEquals("Ache", CheckBoxList.get(i).getText());
}
}
【问题讨论】:
-
您是否尝试过 byModel:angular.github.io/protractor/#/…?
-
@maurycy 我正在使用 Selenium Webdriver。不是量角器..
-
为什么不想使用 xpath?
-
在您的示例中,所有复选框都有名称,如果复选框没有名称,您究竟想显示什么。
-
我看不到“复选框”这样的标签,你的代码应该是
List<WebElement> CheckBoxList = driver.findElements(By.tagName("input"));
标签: angularjs selenium xpath selenium-webdriver