1

I am working on selecting checkboxes(2) randomly using selenium Python. After selection is done, I want to verify the number of checked checkboxes. How to do that?

Below is my code:

checkboxes = driver.find_elements(By.XPATH, "//*[@type='checkbox']")
print(len(checkboxes))
for x in range(2):
    opt = random.choice(checkboxes)
    if opt.is_enabled():
        opt.click()
2
  • 1
    In selenium there is an is_selected() method which can used to check if a checkbox is selected or not. You can refer to this post - stackoverflow.com/questions/14442636/… Commented Mar 2, 2023 at 18:40
  • Update the question with the HTML of the checkbox when 1) Not selected & 2) Selected Commented Mar 2, 2023 at 19:01

0

Your Answer

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.