0
0
Selenium Pythontesting~20 mins

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

Choose your learning style9 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.