0

How to select random checkbox in a table because checkbox id, type , name are same then how to get random checkbox select and value is different.
http://prntscr.com/106nuzd

1
    List<WebElement> a = driver.findElements(By.id("#checkbox"));
    a.get(new Random().nextInt(a.size())).click();

use findElements to get all checkbox and then use Random to generate a random index and click on that webelement in the list

0

You can use this code to select random number of checkboxes,

List<WebElement> a = driver.findElements(By.id("#checkbox"));
Random rand = new Random(); //instance of random class
int int_random = rand.nextInt(a.size()); 
for(int i = 0; i < a.size(); i += int_random) {
    a.get(i).click();
}

This will iterate through the list of all checkboxes with ID="checkbox" and then randomly increment the counter so that the loop doesn't go sequentially selecting all the checkboxes.

2
  • Ignore the previous comment , – PDHide Feb 26 at 5:43
  • Thanks for the help – MS Demo Mar 19 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.