[英]How to check all check-boxes one by one in selenium web driver with the java?
I am using the below code , The test case is not failing but the code is not checking the check-boxes. 我正在使用下面的代码,测试用例没有失败,但是代码没有检查复选框。
@Test(priority=11)
public void Test_CheckBox_Check()throws InterruptedException {
List<WebElement> els = driver.findElements(By.xpath("//md-checkbox[@aria-checked='false']"));
System.out.println(Integer.toString(els.size()));
for ( WebElement el : els ) {
el.click();
}
}
The locator you are using might be the causing the issue try with below: 您正在使用的定位器可能是导致问题的原因,请尝试以下操作:
//div[@class='ng-scope flex-20']//following::md-checkbox**[@role='checkbox']**
You may omit the part in asterisk if all the elements that are identified by md-checkbox are checkboxes. 如果md-checkbox标识的所有元素都是复选框,则可以省略星号中的零件。
Below code worked for me in another case: 下面的代码在另一种情况下对我有用:
List<WebElement> checkboxes = driver.findElements(By.xpath("//div[@class='control-group']//following::input[@type='checkbox']"));
for(WebElement check:checkboxes){
check.click();
}
After adding some wait its working 添加一些后等待其工作
@Test(priority=11)
public void Test_CheckBox_Check()throws InterruptedException {
Thread.sleep(2000);
List<WebElement> els = driver.findElements(By.xpath("//md-checkbox/div/div[@class='md-icon']"));
System.out.println(Integer.toString(els.size()));
for ( WebElement el : els ) {
Thread.sleep(2000);
el.click();
System.out.println(el.getText());
driver.findElement(By.xpath("//div[@class='col-xs-1']")).click();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.