Lakshmi Priya
Lakshmi Priya

Reputation: 9

How to check the multiple number of checkboxes?

In My application, there are 24 checkboxes.

Do I need to find out all the page objects for 24 objects?

EDIT Below is the HTML :

<td>Gender</td>
<td class="text-center"><i class="fa fa-check text-success" />
</td>
<td class="text-center">
  <input class="ng-pristine ng-untouched ng-valid" type="checkbox" ng-checked="permission.friendGender" ng-model="permission.friendGender" />
</td>
<td class="text-center">
  <input class="ng-pristine ng-untouched ng-valid" type="checkbox" ng-checked="permission.anyoneGender" ng-model="permission.anyoneGender" />
</td>

Upvotes: 0

Views: 107

Answers (1)

MKay
MKay

Reputation: 836

I am not privileged to comment on question directly, hence posting a possible solution. I am not sure how your check boxes are structured in HTML. But if your checkbox is with single unique ID having 24 different options, then you can do something similar to :

List<WebElement> CHECKBOXlist = driver.findElements(By.cssSelector("input[type='checkbox']"));
for(WebElement checkbox : CHECKBOXlist)

  {
     //do something with each checkbox.
     System.out.println(checkbox.getText());
     checkbox.click();
 } 

Here you are literally getting all checkboxes with driver.findElements() instead of driver.findElement() (in your case, those 24 check boxes)

Upvotes: 2

Related Questions