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.. :)

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)

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.