Bird
0
0

Which of the following is the correct way to initialize PageFactory elements inside a constructor?

easy📝 Syntax Q12 of 15
Selenium Java - Page Object Model
Which of the following is the correct way to initialize PageFactory elements inside a constructor?
APageFactory.initElements(driver, this);
BPageFactory.initElements(this, driver);
CinitElements(driver, this);
DPageFactory.startElements(driver, this);
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method signature

    The correct method call is PageFactory.initElements(WebDriver driver, Object page).
  2. Step 2: Match parameters in constructor

    Inside the constructor, driver is passed first, then this refers to the current Page Object instance.
  3. Final Answer:

    PageFactory.initElements(driver, this); -> Option A
  4. Quick Check:

    Correct parameter order is driver, then this [OK]
Quick Trick: Remember method signature: driver first, then page object [OK]
Common Mistakes:
  • Swapping driver and this parameters
  • Calling non-existent methods like startElements
  • Omitting PageFactory class name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes