Bird
0
0

What will happen if you forget to call PageFactory.initElements() in your Page Object constructor?

medium📝 Predict Output Q5 of 15
Selenium Java - Page Object Model
What will happen if you forget to call PageFactory.initElements() in your Page Object constructor?
AWebElements will be null and cause NullPointerException when accessed.
BWebElements will be automatically initialized by Selenium.
CTest will pass but elements won't be clickable.
DThe browser will not launch.
Step-by-Step Solution
Solution:
  1. Step 1: Role of initElements in WebElement initialization

    initElements initializes WebElements annotated with @FindBy.
  2. Step 2: Consequence of skipping initElements

    Without initialization, WebElements remain null, causing NullPointerException on use.
  3. Final Answer:

    WebElements will be null and cause NullPointerException when accessed. -> Option A
  4. Quick Check:

    Missing initElements = NullPointerException [OK]
Quick Trick: Always call initElements to avoid NullPointerException [OK]
Common Mistakes:
  • Assuming automatic initialization
  • Thinking test passes silently
  • Confusing with browser launch issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes