Bird
0
0

You want to design a page class for a login page with username, password fields, and a login button. Which design approach is best to follow?

hard📝 Application Q15 of 15
Selenium Java - Page Object Model
You want to design a page class for a login page with username, password fields, and a login button. Which design approach is best to follow?
AStore locators as private By fields; create public methods to enter username, enter password, and click login
BStore WebElement fields publicly and access them directly in tests
CWrite all test steps inside the page class constructor
DUse static methods only without storing any locators
Step-by-Step Solution
Solution:
  1. Step 1: Recall page class design principles

    Locators should be private By fields; actions should be public methods for reuse and encapsulation.
  2. Step 2: Evaluate options

    Store locators as private By fields; create public methods to enter username, enter password, and click login follows best practice by separating locators and actions clearly.
  3. Final Answer:

    Store locators as private By fields; create public methods to enter username, enter password, and click login -> Option A
  4. Quick Check:

    Private locators + public methods = best design [OK]
Quick Trick: Private locators + public action methods = good page class [OK]
Common Mistakes:
MISTAKES
  • Making locators public and exposing WebElements
  • Putting test logic in constructors
  • Using static methods without instance context

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes