Bird
0
0

You want to design a page class for a form with multiple input fields and a submit button. Which design approach best supports easy test maintenance and reusability?

hard📝 Application Q8 of 15
Selenium Java - Page Object Model
You want to design a page class for a form with multiple input fields and a submit button. Which design approach best supports easy test maintenance and reusability?
AUse public static WebElement fields for all elements to access them globally
BWrite all element locators and actions directly inside each test method
CAvoid using PageFactory and locate elements dynamically in each method
DCreate private WebElement fields for each input and button, with public methods to set values and submit
Step-by-Step Solution
Solution:
  1. Step 1: Identify maintainable design

    Private fields with public methods encapsulate element details and allow reuse.
  2. Step 2: Compare options

    Create private WebElement fields for each input and button, with public methods to set values and submit follows POM best practices. The other options reduce maintainability or reusability.
  3. Final Answer:

    Create private WebElement fields for each input and button, with public methods to set values and submit -> Option D
  4. Quick Check:

    Private fields + public methods = maintainable page class [OK]
Quick Trick: Encapsulate elements as private fields with public action methods [OK]
Common Mistakes:
  • Scattering locators in test methods
  • Using public static fields for elements
  • Avoiding PageFactory without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes