Challenge - 5 Problems
Radio Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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')
Attempts:
2 left
💡 Hint
Check how the loop and break statement work with is_selected()
✗ Incorrect
The code loops through all radio buttons named 'color'. It prints the value of the first one that is selected and then stops. If none are selected, it prints 'No selection'.
❓ assertion
intermediate1: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')Attempts:
2 left
💡 Hint
Use the method that checks selection state directly.
✗ Incorrect
The is_selected() method returns True if the radio button is selected. Checking 'checked' attribute or 'value' does not reliably confirm selection.
❓ locator
advanced2: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?
Attempts:
2 left
💡 Hint
Consider the relationship between label and input elements.
✗ Incorrect
Option A uses XPath to find the input radio button that is a sibling before the label with text 'Male', which directly associates the label text with the radio button. Other options may not uniquely identify the correct radio button.
🔧 Debug
advanced2: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?
Attempts:
2 left
💡 Hint
Check if the element can be clicked or is enabled.
✗ Incorrect
If the radio button is disabled or hidden, click() will not select it. The locator is assumed correct here. click() works on radio buttons. Page loading issues usually cause exceptions.
❓ framework
expert3: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?
Attempts:
2 left
💡 Hint
Count how many radio buttons are selected, not just check one.
✗ Incorrect
Option D collects all selected radio buttons and asserts exactly one is selected. Other options only check one element or if any is selected, not ensuring exactly one.