A radio button is a web element that allows the user to select only one option from a set of choices. Selecting one option automatically deselects the others.
Click to reveal answer
beginner
How do you locate a radio button using Selenium in Java?
You can locate a radio button using locators like By.id, By.name, or By.xpath. For example: driver.findElement(By.id("genderMale"))
Click to reveal answer
beginner
How to check if a radio button is selected in Selenium Java?
Use the isSelected() method on the WebElement. It returns true if the radio button is selected, otherwise false.
Click to reveal answer
beginner
How to select a radio button using Selenium Java?
Call the click() method on the WebElement representing the radio button. This simulates a user clicking and selecting it.
Click to reveal answer
intermediate
Why should you verify a radio button's state after clicking it?
Because sometimes the click might not work due to page issues or scripts. Verifying with isSelected() ensures the radio button is actually selected.
Click to reveal answer
Which Selenium method checks if a radio button is selected?
AisSelected()
BisEnabled()
CisDisplayed()
DgetText()
✗ Incorrect
The isSelected() method returns true if the radio button is selected.
What happens when you select one radio button in a group?
AAll radio buttons get selected
BOnly the clicked radio button is selected, others deselect
CNothing changes
DAll radio buttons get deselected
✗ Incorrect
Radio buttons allow only one selection in a group; selecting one deselects others.
Which locator is best to uniquely identify a radio button?
ABy.id
BBy.tagName
CBy.className
DBy.linkText
✗ Incorrect
By.id is usually unique and best for locating a specific radio button.
What Selenium method simulates clicking a radio button?
AsendKeys()
Bsubmit()
Cclick()
Dclear()
✗ Incorrect
click() simulates a user clicking the radio button.
If a radio button is not selected after click(), what should you do?
AIgnore it
BRefresh the page only
CUse getText() to verify
DCheck if the element is enabled and visible
✗ Incorrect
Check if the radio button is enabled and visible to ensure it can be clicked.
Explain how to select and verify a radio button using Selenium in Java.
Think about the steps a user takes and how Selenium mimics them.
You got /3 concepts.
Describe why radio buttons allow only one selection and how this affects test automation.
Consider real-life examples like choosing gender or payment method.
You got /3 concepts.
Practice
(1/5)
1. What does the isSelected() 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. Finds the radio button element on the page
Solution
Step 1: Understand the purpose of isSelected()
This method checks the current state of a radio button or checkbox to see if it is selected or not.
Step 2: Differentiate from other methods
click() selects the radio button, but isSelected() only checks selection status without changing it.
Final Answer:
Checks if the radio button is currently selected -> Option A
Quick Check:
isSelected() = Check selection status [OK]
Hint: Remember: isSelected() checks state, click() changes state [OK]
Common Mistakes:
Confusing isSelected() with click()
Expecting isSelected() to select the button
Using getText() to check selection
2. Which of the following is the correct way to select a radio button using Selenium WebDriver in Java?
easy
A. driver.findElement(By.id("option1")).isSelected();
B. driver.findElement(By.id("option1")).sendKeys("select");
C. driver.findElement(By.id("option1")).getText();
D. driver.findElement(By.id("option1")).click();
Solution
Step 1: Identify the method to select a radio button
To select a radio button, you use the click() method on the WebElement.
Step 2: Check other options for correctness
isSelected() only checks selection, getText() returns label text, and sendKeys() is not used for radio buttons.
Final Answer:
driver.findElement(By.id("option1")).click(); -> Option D
Quick Check:
Use click() to select radio button [OK]
Hint: Use click() to select radio buttons, not isSelected() [OK]
Hint: Only one radio button in group is selected at a time [OK]
Common Mistakes:
Assuming both radio buttons can be selected simultaneously
Confusing isSelected() return values
Not understanding radio button group behavior
4. You have the following code to select a radio button:
WebElement radio = driver.findElement(By.name("gender"));
radio.click();
But the test fails because the wrong radio button is selected. What is the likely problem?
medium
A. The findElement method is incorrect; should use findElements
B. The click() method does not work on radio buttons
C. Using By.name returns multiple elements; need to specify which one
D. Radio buttons cannot be selected by Selenium
Solution
Step 1: Analyze locator usage
Using By.name("gender") returns the first matching element, but if multiple radio buttons share the same name, this may select the wrong one.
Step 2: Fix by specifying correct element
To select the intended radio button, use a more specific locator or find all elements and choose the correct one.
Final Answer:
Using By.name returns multiple elements; need to specify which one -> Option C
Quick Check:
Locator must uniquely identify radio button [OK]
Hint: Use unique locators or filter elements to select correct radio button [OK]
Common Mistakes:
Assuming findElement returns all matching elements
Thinking click() doesn't work on radio buttons
Ignoring that multiple radios share the same name attribute
5. You want to write a test to verify that selecting one radio button deselects the others in the same group. Which approach is best to implement this in Selenium Java?
hard
A. Click all radio buttons one by one and assert they are all selected
B. Click one radio button, then assert it is selected and all others are not selected
C. Use sendKeys() to select radio buttons and check their text
D. Check only the first radio button's selection status without clicking
Solution
Step 1: Understand radio button group behavior
Only one radio button in a group can be selected at a time; selecting one deselects others.
Step 2: Write assertions to verify this
Click one radio button, then check that it is selected and all others are not selected to confirm correct behavior.
Final Answer:
Click one radio button, then assert it is selected and all others are not selected -> Option B
Quick Check:
Test selection exclusivity by asserting one selected, others not [OK]
Hint: Assert one selected and others deselected after click [OK]
Common Mistakes:
Expecting multiple radio buttons to be selected simultaneously
Not asserting other buttons are deselected
Using sendKeys() instead of click()
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.