简体   繁体   English

如何 select 硒(java)中的多个复选框?

[英]How to select multiple checkboxes in selenium(java)?

I am trying to select all checkboxes whose value is matched to my value.我正在尝试 select 所有值与我的值匹配的复选框。 Code is working fine when the web page has no vertical scroll.当 web 页面没有垂直滚动时,代码工作正常。 But if web page has some more data then the checkbox is not selected as I want.但是,如果 web 页面有更多数据,则不会按我的意愿选中该复选框。

Here is my code-这是我的代码-

List<WebElement> rselect = tagdis1.findElements(By.className("row-selection-checkbox"));
System.out.println("Row selection Size- " + rselect.size());
List<WebElement> record = driver.findElements(By.id("$ctrl.item.id"));
System.out.println("Size- " + record.size());
int DocNameCount = 0;

for (int j = 0; j < record.size(); j++) {

    String Pname = record.get(j).getText();
    System.out.println("Pdf name- " + Pname);

    if (Pname.equals(docName + ".pdf")) {
       // here total 4 records i get but able to click only on 3 records
        System.out.println(j + " " + Pname);
        rselect.get(j).click();
        Thread.sleep(2000); 
    }
}

Please use scroll option in your operation,请在您的操作中使用滚动选项,

/*
 * By
 * scroll to the element and wait
 */
public void scroll(By element){
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].scrollIntoView(true);",driver.findElement(element));
    log.info("Scrolling down");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM