0
0
Selenium Pythontesting~10 mins

Checkbox interactions in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to click the checkbox element.

Selenium Python
checkbox = driver.find_element(By.ID, "subscribe")
checkbox.[1]()
Drag options to blanks, or click blank then click option'
Aclick
Bsend_keys
Cclear
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using send_keys instead of click to select the checkbox.
Trying to clear a checkbox which is not applicable.
2fill in blank
medium

Complete the code to check if the checkbox is selected.

Selenium Python
checkbox = driver.find_element(By.ID, "agree")
is_checked = checkbox.[1]()
Drag options to blanks, or click blank then click option'
Ais_enabled()
Bis_selected()
Cis_displayed()
Dis_checked()
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_displayed() which checks visibility, not selection.
Using a non-existent method is_checked().
3fill in blank
hard

Fix the error in the code to uncheck the checkbox if it is selected.

Selenium Python
checkbox = driver.find_element(By.ID, "notify")
if checkbox.[1]():
    checkbox.click()
Drag options to blanks, or click blank then click option'
Ais_enabled
Bis_displayed
Cis_selected
Dis_checked
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_enabled() which checks if element is interactable, not selected.
Using is_displayed() which checks visibility, not selection.
4fill in blank
hard

Fill both blanks to select the checkbox only if it is not already selected.

Selenium Python
checkbox = driver.find_element(By.ID, "terms")
if not checkbox.[1]():
    checkbox.[2]()
Drag options to blanks, or click blank then click option'
Ais_selected
Bclick
Cis_enabled
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using clear() to uncheck which is not valid for checkboxes.
Checking is_enabled() instead of is_selected().
5fill in blank
hard

Fill all three blanks to create a function that toggles a checkbox by its ID.

Selenium Python
def toggle_checkbox(driver, checkbox_id):
    checkbox = driver.find_element(By.ID, [1])
    if checkbox.[2]():
        checkbox.[3]()
Drag options to blanks, or click blank then click option'
Acheckbox_id
Bis_selected
Cclick
D"terms"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed string instead of the variable for the ID.
Using is_enabled() instead of is_selected() for checking.
Not clicking to toggle the checkbox.