Page Object Model (POM) is a design pattern used in Selenium frameworks to create object repositories for web elements. Each web page is represented as a separate Java class. Locators (elements) are variables, and user actions (like click, enter text) are methods inside that class. This helps reduce code duplication, improve readability, and make maintenance easier.
We use @FindBy annotations to capture locators like ID, name, XPath, etc., and define them as private WebElements for encapsulation. Then, we use a constructor to initialize these elements with PageFactory.initElements(driver, this). If needed, we create getter and setter methods to access elements indirectly. Action methods like enterUsername or clickLogin are defined inside the same class. This approach makes the code reusable, maintainable, and keeps the test scripts clean.
@FindBy annotations and PageFactory.initElements() to initialize elements.@FindBy – Locate a web element using a single locator (id, name, xpath, css, etc.).@FindBys – Locate an element with multiple conditions (AND logic).@FindAll – Locate an element with multiple conditions (OR logic).@CacheLookup – Cache the web element after the first lookup to improve performance.
Signup