Bird
0
0

Which of the following is the correct way to instantiate a page object in a Selenium Java test class?

easy📝 Syntax Q12 of 15
Selenium Java - Page Object Model
Which of the following is the correct way to instantiate a page object in a Selenium Java test class?
ALoginPage login = new LoginPage(driver);
BLoginPage login = LoginPage();
CLoginPage login = new LoginPage();
DLoginPage login = driver.get(LoginPage.class);
Step-by-Step Solution
Solution:
  1. Step 1: Recall page object constructor usage

    Page objects usually require WebDriver passed to constructor for element initialization.
  2. Step 2: Check each option for correct syntax

    LoginPage login = new LoginPage(driver); correctly uses 'new' with driver argument. Others miss driver or use invalid syntax.
  3. Final Answer:

    LoginPage login = new LoginPage(driver); -> Option A
  4. Quick Check:

    Use 'new' with driver parameter [OK]
Quick Trick: Always pass driver to page object constructor [OK]
Common Mistakes:
MISTAKES
  • Forgetting to pass driver to constructor
  • Using constructor without 'new' keyword
  • Trying to get page object from driver directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes