Bird
0
0

Consider the following code snippet:

medium📝 Predict Output Q13 of 15
Selenium Java - Handling Form Elements
Consider the following code snippet:
WebElement rb1 = driver.findElement(By.id("radio1"));
WebElement rb2 = driver.findElement(By.id("radio2"));
rb1.click();
boolean selected1 = rb1.isSelected();
boolean selected2 = rb2.isSelected();
What will be the values of selected1 and selected2 after execution?
Aselected1 = true, selected2 = false
Bselected1 = false, selected2 = true
Cselected1 = true, selected2 = true
Dselected1 = false, selected2 = false
Step-by-Step Solution
Solution:
  1. Step 1: Understand radio button behavior on click

    Clicking rb1 selects it and deselects other radio buttons in the same group, so rb1.isSelected() returns true and rb2.isSelected() returns false.
  2. Step 2: Confirm the boolean values

    Therefore, selected1 is true and selected2 is false after clicking rb1.
  3. Final Answer:

    selected1 = true, selected2 = false -> Option A
  4. Quick Check:

    Click selects one, others deselect = true/false [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes