0

This is the how my HTML looks like:

 <tr>
 <td class = 'text-bar'> id </td>
 <td>
 <input type="checkbox" size = "20" value= 'Yes' id ="x_id1">
 </td>
 </tr>
 .
 .
 .

I have 19 checkboxes and I want to select checkboxes in-between.

what would be the easiest way to achieve that:

My current code looks like this which selects all the checkboxes right now. How do i add if condition to select particular checkboxes in-between ??:

checkboxes = driver.find_elements_by_css_selector("input[type='checkbox']")
 for checkbox in checkboxes:
 if not checkbox.is_selected():
 checkbox.click()
 time.sleep(1)

Appreciate your help.. :)

asked Jun 21, 2021 at 20:50

1 Answer 1

0

This is what I came up with to select particular checkboxes by converting them into a list. In my code, I am trying to select checkboxes between 3 and 15 (which is not dynamic but this is what I was looking for:

checkboxes = driver.find_elements_by_css_selector("input[type= 'checkbox']")
 chk = [checkbox for checkbox in checkboxes]
 for i in chk[4:15]:
 if not i.is_selected():
 i.click()
 time.sleep(1)
answered Jun 22, 2021 at 15:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.