Bird
0
0

Consider this action method:

medium📝 Predict Output Q5 of 15
Selenium Java - Page Object Model
Consider this action method:
public void selectOption(String option) {
    dropdown.click();
    driver.findElement(By.xpath("//option[text()='" + option + "']")).click();
}

What will happen if the option text does not exist in the dropdown?
ANo action occurs and the method completes silently
BThe first option in the dropdown is selected by default
CThe dropdown closes without selecting any option
DA NoSuchElementException is thrown at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Understand findElement behavior

    driver.findElement throws NoSuchElementException if the element is not found.
  2. Step 2: Apply to the given method

    If the option text does not exist, the xpath search fails and exception is thrown.
  3. Final Answer:

    A NoSuchElementException is thrown at runtime -> Option D
  4. Quick Check:

    findElement missing element = NoSuchElementException [OK]
Quick Trick: findElement throws exception if element missing [OK]
Common Mistakes:
  • Assuming method completes silently without error
  • Thinking dropdown auto-selects first option
  • Believing dropdown just closes without selection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes