0
0
Selenium Javatesting~20 mins

Radio button handling in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Radio Button Master
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 Java code snippet?
Consider the following Selenium Java code that tries to select a radio button and print its status. What will be printed?
Selenium Java
WebElement radioBtn = driver.findElement(By.id("option1"));
radioBtn.click();
System.out.println(radioBtn.isSelected());
AElementNotInteractableException
Bfalse
CNoSuchElementException
Dtrue
Attempts:
2 left
💡 Hint
Clicking a radio button sets it as selected, so isSelected() returns true.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a radio button is selected in Selenium Java?
You want to assert that a radio button with id 'genderMale' is selected. Which assertion is correct?
AassertEquals(driver.findElement(By.id("genderMale")).getText(), "selected");
BassertFalse(driver.findElement(By.id("genderMale")).isDisplayed());
CassertTrue(driver.findElement(By.id("genderMale")).isSelected());
DassertNull(driver.findElement(By.id("genderMale")).getAttribute("checked"));
Attempts:
2 left
💡 Hint
Use isSelected() to check if a radio button is selected.
locator
advanced
2:00remaining
Which locator is best to select a radio button with label text 'Subscribe'?
You want to select the radio button associated with the label text 'Subscribe'. Which locator is best?
ABy.xpath("//label[text()='Subscribe']/preceding-sibling::input[@type='radio']")
BBy.id("Subscribe")
CBy.cssSelector("input[type='radio'][value='Subscribe']")
DBy.name("Subscribe")
Attempts:
2 left
💡 Hint
Use XPath to find input radio before label with exact text.
🔧 Debug
advanced
2:00remaining
Why does this Selenium Java code fail to select the radio button?
Given this code snippet, why does the radio button not get selected? WebElement radio = driver.findElement(By.name("choice")); radiobutton.click();
AThe click() method requires JavaScript executor for radio buttons.
BVariable name 'radiobutton' is undefined; should be 'radio'.
CRadio buttons cannot be clicked using Selenium WebDriver.
DThe locator By.name("choice") is incorrect for radio buttons.
Attempts:
2 left
💡 Hint
Check variable names carefully for typos.
framework
expert
3:00remaining
In a Selenium Java test framework, which method best ensures a radio button is selected before proceeding?
You want to create a reusable method that selects a radio button only if it is not already selected. Which method implementation is best?
A
public void selectRadioButton(WebElement radio) {
  if (!radio.isSelected()) {
    radio.click();
  }
}
B
public void selectRadioButton(WebElement radio) {
  radio.click();
}
C
public void selectRadioButton(WebElement radio) {
  if (radio.isDisplayed()) {
    radio.click();
  }
}
D
public void selectRadioButton(WebElement radio) {
  if (radio.getAttribute("checked") == null) {
    radio.click();
  }
}
Attempts:
2 left
💡 Hint
Check selection status before clicking to avoid unnecessary actions.