Bird
Raised Fist0
Selenium Pythontesting~20 mins

Radio button interactions in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Radio Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Selenium Python code snippet?
Given a webpage with radio buttons named 'color' and the following Selenium code, what will be printed?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By

# Assume driver is already initialized and page loaded
radio_buttons = driver.find_elements(By.NAME, 'color')
for rb in radio_buttons:
    if rb.is_selected():
        print(rb.get_attribute('value'))
        break
else:
    print('No selection')
APrints 'No selection' even if a radio button is selected
BPrints all values of all radio buttons regardless of selection
CPrints the value attribute of the first selected radio button
DRaises NoSuchElementException if no radio button is selected
Attempts:
2 left
💡 Hint
Check how the loop and break statement work with is_selected()
❓ assertion
intermediate
1:30remaining
Which assertion correctly verifies a radio button is selected?
You want to assert that the radio button with id 'option1' is selected. Which assertion is correct in Selenium Python?
Selenium Python
radio_button = driver.find_element(By.ID, 'option1')
Aassert radio_button.is_selected() == True
Bassert radio_button.get_attribute('checked') == 'false'
Cassert radio_button.is_displayed()
Dassert radio_button.get_attribute('value') == 'selected'
Attempts:
2 left
💡 Hint
Use the method that checks selection state directly.
❓ locator
advanced
2:30remaining
Which locator is best to select a radio button with label text 'Male'?
You want to select the radio button associated with the label text 'Male'. Which locator is the best practice in Selenium Python?
Adriver.find_element(By.XPATH, "//label[text()='Male']/preceding-sibling::input[@type='radio']")
Bdriver.find_element(By.ID, 'maleRadio')
Cdriver.find_element(By.CSS_SELECTOR, "input[type='radio'][value='Male']")
Ddriver.find_element(By.NAME, 'gender')
Attempts:
2 left
💡 Hint
Consider the relationship between label and input elements.
🔧 Debug
advanced
2:30remaining
Why does this Selenium Python code fail to select a radio button?
Code snippet: radio_button = driver.find_element(By.ID, 'option2') radio_button.click() But the radio button remains unselected after running. What is the most likely reason?
AThe locator ID 'option2' is incorrect and finds no element
BThe radio button is disabled or not interactable
CThe click() method does not work on radio buttons
DThe page has not finished loading before click()
Attempts:
2 left
💡 Hint
Check if the element can be clicked or is enabled.
❓ framework
expert
3:00remaining
In a test framework, how to best verify only one radio button is selected among a group?
You have a group of radio buttons named 'payment'. Which approach best verifies exactly one is selected using Selenium Python?
Aassert any(rb.is_selected() for rb in driver.find_elements(By.NAME, 'payment'))
Bassert driver.find_element(By.NAME, 'payment').is_selected()
Cassert driver.find_elements(By.NAME, 'payment')[0].is_selected()
Dselected = [rb for rb in driver.find_elements(By.NAME, 'payment') if rb.is_selected()]; assert len(selected) == 1
Attempts:
2 left
💡 Hint
Count how many radio buttons are selected, not just check one.

Practice

(1/5)
1. What does the is_selected() method do when used on a radio button element in Selenium?
easy
A. Checks if the radio button is currently selected
B. Clicks the radio button to select it
C. Returns the text label of the radio button
D. Clears the selection of the radio button

Solution

  1. Step 1: Understand the purpose of is_selected()

    This method checks the current state of a radio button or checkbox to see if it is selected or not.
  2. Step 2: Compare with other actions

    Unlike click() which changes the state, is_selected() only returns a boolean indicating selection status.
  3. Final Answer:

    Checks if the radio button is currently selected -> Option A
  4. Quick Check:

    Check selection status = C [OK]
Hint: Remember: is_selected() checks state, click() changes it [OK]
Common Mistakes:
  • Confusing is_selected() with click()
  • Expecting is_selected() to select the button
  • Using is_selected() to get button text
2. Which of the following is the correct way to select a radio button with Selenium in Python?
easy
A. driver.find_element(By.ID, 'option1').choose()
B. driver.find_element(By.ID, 'option1').select()
C. driver.find_element(By.ID, 'option1').check()
D. driver.find_element(By.ID, 'option1').click()

Solution

  1. Step 1: Identify the correct method to select a radio button

    In Selenium, click() is used to select radio buttons or checkboxes.
  2. Step 2: Verify method names

    Methods like select(), check(), or choose() do not exist in Selenium WebDriver API.
  3. Final Answer:

    driver.find_element(By.ID, 'option1').click() -> Option D
  4. Quick Check:

    Use click() to select radio buttons = A [OK]
Hint: Use click() to select radio buttons, no select() method [OK]
Common Mistakes:
  • Using non-existent methods like select()
  • Trying to assign value instead of clicking
  • Confusing with form select elements
3. Consider this code snippet:
radio1 = driver.find_element(By.ID, 'r1')
radio2 = driver.find_element(By.ID, 'r2')
radio1.click()
print(radio1.is_selected())
print(radio2.is_selected())

What will be the output if these are radio buttons in the same group?
medium
A. True\nFalse
B. False\nTrue
C. True\nTrue
D. False\nFalse

Solution

  1. Step 1: Understand radio button group behavior

    Clicking one radio button selects it and deselects others in the same group.
  2. Step 2: Analyze the code output

    After clicking radio1, radio1.is_selected() returns True, and radio2.is_selected() returns False.
  3. Final Answer:

    True False -> Option A
  4. Quick Check:

    One selected, others deselected = B [OK]
Hint: Only one radio button in group is selected at a time [OK]
Common Mistakes:
  • Assuming both radio buttons can be selected
  • Confusing is_selected() output order
  • Ignoring group behavior of radio buttons
4. You wrote this code to select a radio button:
radio = driver.find_element(By.NAME, 'gender')
radio.click()

But it always selects the first radio button in the group, not the intended one. What is the likely problem?
medium
A. The click() method is incorrect for radio buttons
B. Using By.NAME returns multiple elements; need to specify which one
C. Radio buttons cannot be selected by Selenium
D. The radio button is disabled and cannot be clicked

Solution

  1. Step 1: Understand how find_element(By.NAME) works

    This method returns the first matching element with the given name attribute.
  2. Step 2: Identify the issue with multiple radio buttons sharing the same name

    Radio buttons in a group share the same name, so you must select the correct one by index or another attribute.
  3. Final Answer:

    Using By.NAME returns multiple elements; need to specify which one -> Option B
  4. Quick Check:

    By.NAME returns first element only = A [OK]
Hint: Use find_elements and index to pick correct radio button [OK]
Common Mistakes:
  • Assuming By.NAME returns all elements
  • Using click() incorrectly
  • Ignoring radio button group naming
5. You want to write a test to verify that selecting one radio button deselects the others in the same group. Which code snippet correctly performs this check?
hard
A. radio_buttons = driver.find_elements(By.ID, 'color') radio_buttons[0].click() assert radio_buttons[1].is_selected()
B. radio_buttons = driver.find_element(By.NAME, 'color') radio_buttons.click() assert radio_buttons.is_selected()
C. radio_buttons = driver.find_elements(By.NAME, 'color') radio_buttons[1].click() assert radio_buttons[1].is_selected() and not radio_buttons[0].is_selected()
D. radio_buttons = driver.find_elements(By.CLASS_NAME, 'color') radio_buttons.click() assert radio_buttons[0].is_selected()

Solution

  1. Step 1: Select all radio buttons by group name

    Use find_elements(By.NAME, 'color') to get all radio buttons in the group.
  2. Step 2: Click one button and assert selection states

    Click the second button, then assert it is selected and the first is not.
  3. Final Answer:

    radio_buttons = driver.find_elements(By.NAME, 'color') radio_buttons[1].click() assert radio_buttons[1].is_selected() and not radio_buttons[0].is_selected() -> Option C
  4. Quick Check:

    Click one, check selected and deselected = D [OK]
Hint: Use find_elements and assert one selected, others not [OK]
Common Mistakes:
  • Using find_element instead of find_elements
  • Not checking deselection of other buttons
  • Wrong locator type for radio group
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard