Page Object Model (POM) is a design pattern used in Selenium for creating an object repository for web UI elements. The POM model separates the web UI elements and their associated methods into their own classes, which can be easily maintained and updated. This design pattern helps to reduce code redundancy, improve code reusability, and make test automation scripts more maintainable.
To implement POM in Selenium, you need to create a separate class for each page of your web application. Each class should contain a set of web UI elements and methods that interact with those elements. These methods should perform actions like clicking buttons, entering text, or verifying the presence of elements.
Here's an example of a POM class in Selenium:
public class LoginPage {
private WebDriver driver;
private By usernameField = By.id("username");
private By passwordField = By.id("password");
private By loginButton = By.id("login");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public void setUsername(String username) {
driver.findElement(usernameField).sendKeys(username);
}
public void setPassword(String password) {
driver.findElement(passwordField).sendKeys(password);
}
public void clickLoginButton() {
driver.findElement(loginButton).click();
}
}
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article