0
0
Selenium Pythontesting~10 mins

Radio button 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 select a radio button by its ID.

Selenium Python
driver.find_element(By.ID, [1]).click()
Drag options to blanks, or click blank then click option'
A"checkbox1"
B"radio1"
C"submit"
D"button1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong ID that does not belong to a radio button.
Trying to select a checkbox or button instead of a radio button.
2fill in blank
medium

Complete the code to check if a radio button is selected.

Selenium Python
is_selected = driver.find_element(By.NAME, [1]).is_selected()
Drag options to blanks, or click blank then click option'
A"option"
B"submit"
C"radio"
D"gender"
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect name attribute that does not match the radio buttons.
Confusing the name attribute with the ID.
3fill in blank
hard

Fix the error in the code to select a radio button using XPath.

Selenium Python
driver.find_element(By.XPATH, [1]).click()
Drag options to blanks, or click blank then click option'
A"//input[@type='radio' and @value='male']"
B"//button[@type='radio' and @value='male']"
C"//input[@type='checkbox' and @value='male']"
D"//input[@type='radio' and @name='female']"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'button' instead of 'input' in XPath.
Selecting checkboxes instead of radio buttons.
Using wrong attribute values.
4fill in blank
hard

Fill both blanks to create a function that selects a radio button by its value attribute.

Selenium Python
def select_radio_by_value(driver, value):
    radio = driver.find_element(By.CSS_SELECTOR, "input[type='radio'][value='" + [1] + "']")
    if not radio.[2]():
        radio.click()
Drag options to blanks, or click blank then click option'
Avalue
Bis_selected
Cis_enabled
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong attribute name in the CSS selector.
Checking if the radio button is enabled instead of selected.
5fill in blank
hard

Fill all three blanks to create a test that verifies the correct radio button is selected after clicking.

Selenium Python
def test_radio_selection(driver):
    driver.get("http://example.com/radio")
    radio_buttons = driver.find_elements(By.NAME, [1])
    radio_buttons[[2]].click()
    assert radio_buttons[[3]].is_selected(), "Radio button not selected as expected"
Drag options to blanks, or click blank then click option'
A"gender"
B1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong name attribute.
Clicking and asserting different indexes.
Forgetting that indexes start at 0.