A radio button is a small circle on a web page that allows the user to select one option from a group of choices. Only one radio button in the group can be selected at a time.
Click to reveal answer
beginner
How do you locate a radio button using Selenium in Python?
You can locate a radio button using locators like find_element(By.ID, 'id_value'), find_element(By.NAME, 'name_value'), or find_element(By.CSS_SELECTOR, 'input[type="radio"]').
Click to reveal answer
beginner
How do you select a radio button using Selenium in Python?
First, locate the radio button element, then call element.click() to select it. Selenium will simulate a user clicking the radio button.
Click to reveal answer
beginner
How can you verify if a radio button is selected in Selenium Python?
Use the element.is_selected() method. It returns True if the radio button is selected, otherwise False.
Click to reveal answer
intermediate
Why should you avoid using absolute XPath for locating radio buttons?
Absolute XPath is fragile because it depends on the full path in the HTML structure. If the page layout changes, the locator breaks. Use relative XPath or other locators like ID or name for stability.
Click to reveal answer
Which Selenium method is used to check if a radio button is selected?
Aclick()
Bis_enabled()
Cis_displayed()
Dis_selected()
✗ Incorrect
The method is_selected() returns True if the radio button is selected.
What happens when you click a radio button in a group?
AAll radio buttons in the group get selected
BOnly the clicked radio button gets selected
CNo radio button gets selected
DThe radio button toggles between selected and unselected
✗ Incorrect
Only one radio button in a group can be selected at a time. Clicking selects that one.
Which locator is best to find a radio button reliably?
AID or Name attribute
BAbsolute XPath
CIndex number
DText content
✗ Incorrect
ID or Name attributes are stable and reliable locators for radio buttons.
What does the Selenium click() method do on a radio button?
AChecks if the radio button is visible
BDeletes the radio button
CSelects the radio button
DReturns the radio button value
✗ Incorrect
click() simulates a user clicking the radio button, selecting it.
If a radio button is not selectable, which Selenium method helps check if it is enabled?
Ais_enabled()
Bis_selected()
Cis_displayed()
Dget_attribute()
✗ Incorrect
is_enabled() returns True if the element is enabled and can be interacted with.
Explain how to select and verify a radio button using Selenium in Python.
Think about the steps a user takes to click and check a radio button.
You got /3 concepts.
Describe best practices for locating radio buttons in Selenium tests.
Consider what makes a locator reliable and easy to maintain.
You got /3 concepts.
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
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.
Step 2: Compare with other actions
Unlike click() which changes the state, is_selected() only returns a boolean indicating selection status.
Final Answer:
Checks if the radio button is currently selected -> Option A
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
Step 1: Identify the correct method to select a radio button
In Selenium, click() is used to select radio buttons or checkboxes.
Step 2: Verify method names
Methods like select(), check(), or choose() do not exist in Selenium WebDriver API.
Final Answer:
driver.find_element(By.ID, 'option1').click() -> Option D
Quick Check:
Use click() to select radio buttons = A [OK]
Hint: Use click() to select radio buttons, no select() method [OK]
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
Step 1: Understand radio button group behavior
Clicking one radio button selects it and deselects others in the same group.
Step 2: Analyze the code output
After clicking radio1, radio1.is_selected() returns True, and radio2.is_selected() returns False.
Final Answer:
True
False -> Option A
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
Step 1: Understand how find_element(By.NAME) works
This method returns the first matching element with the given name attribute.
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.
Final Answer:
Using By.NAME returns multiple elements; need to specify which one -> Option B
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
Step 1: Select all radio buttons by group name
Use find_elements(By.NAME, 'color') to get all radio buttons in the group.
Step 2: Click one button and assert selection states
Click the second button, then assert it is selected and the first is not.
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
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 unknownstrongwhile earning +1 Grip toward your certificate.