Bird
0
0

Given the code snippet:

medium📝 Predict Output Q4 of 15
Selenium Java - Handling Form Elements
Given the code snippet:
WebElement rb = driver.findElement(By.name("gender"));
rb.click();
boolean selected = rb.isSelected();
System.out.println(selected);

What will be printed if the radio button was not selected before?
Atrue
Bfalse
Cnull
DException thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand click() effect on radio button

    Clicking a radio button selects it if it was not selected before.
  2. Step 2: Check isSelected() after click

    After clicking, isSelected() returns true, so printed value is true.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    Click selects radio button = isSelected() true [OK]
Quick Trick: Clicking selects radio button, isSelected() returns true [OK]
Common Mistakes:
  • Assuming isSelected() returns false after click
  • Expecting null or exception without reason
  • Confusing radio button with checkbox behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes