Page Object Model (POM)
What is POM?
The Page Object Model is a design pattern where each web page (or component) is represented as a Java class, encapsulating its locators and the actions that can be performed on it.
Example
public class LoginPage {
WebDriver driver;
By username = By.id("username");
By password = By.id("password");
By loginBtn = By.id("login");
public LoginPage(WebDriver driver) { this.driver = driver; }
public void login(String user, String pass) {
driver.findElement(username).sendKeys(user);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginBtn).click();
}
}
Why POM Is Widely Used
If a locator changes, it only needs updating in one page class rather than in every test that uses it — dramatically improving maintainability as a suite grows.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.
.png)