Bird
0
0

Consider this page class method:

medium📝 Predict Output Q5 of 15
Selenium Java - Page Object Model
Consider this page class method:
public void clickSubmit() {
  submitButton.click();
}

If submitButton is not initialized properly, what will happen when clickSubmit() is called?
AThe test passes silently
BMethod executes without error but does nothing
CNoSuchElementException is thrown immediately
DNullPointerException is thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand uninitialized WebElement behavior

    If submitButton is null (not initialized), calling click() on it causes NullPointerException.
  2. Step 2: Differentiate exceptions

    NoSuchElementException occurs when element is searched but not found, not when variable is null.
  3. Final Answer:

    NullPointerException is thrown -> Option D
  4. Quick Check:

    Uninitialized WebElement click = NullPointerException [OK]
Quick Trick: Uninitialized WebElement causes NullPointerException on method call [OK]
Common Mistakes:
  • Confusing NullPointerException with NoSuchElementException
  • Assuming method does nothing if element is null
  • Thinking test passes silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes