Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Selenium Java - Handling Form Elements
Identify the error in the following code snippet:
WebElement rb = driver.findElement(By.id("genderMale"));
if(rb.isSelected() = false) {
  rb.click();
}
AMissing semicolon after rb.click()
BNo error, code is correct
CIncorrect locator method used
DUsing assignment '=' instead of comparison '==' in if condition
Step-by-Step Solution
Solution:
  1. Step 1: Check if condition syntax

    The condition uses '=' which is assignment, not comparison.
  2. Step 2: Correct syntax for comparison

    It should use '==' or better '!rb.isSelected()' to compare boolean values.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in if condition -> Option D
  4. Quick Check:

    Use '==' for comparison, not '=' [OK]
Quick Trick: Use '==' or '!' for boolean checks, not '=' [OK]
Common Mistakes:
  • Using '=' instead of '==' in conditions
  • Ignoring syntax errors in if statements
  • Assuming missing semicolon causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes