简体   繁体   中英

How to select multiple checkboxes in selenium(java)?

I am trying to select all checkboxes whose value is matched to my value. Code is working fine when the web page has no vertical scroll. But if web page has some more data then the checkbox is not selected as I want.

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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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