# Page Object Model

Page Object Model is a design pattern in Selenium that defines page classes for each web page. It has the following benefits:

1. Maintainability: If the UI of the web page changes, only the page object class needs to be updated, not the test scripts.
2. Readability: The page object classes act as an abstraction layer, making the test scripts more readable.
3. Reusability: The page object classes can be reused across multiple test scripts.

How it works:

1. Create a page class for each web page.&#x20;

This class will contain:

* WebElements as fields
* Methods to represent actions on that page

For example: LoginPage class for the login page will have:

```java
public class LoginPage {
    
private WebElement usernameField;

private WebElement passwordField;

private WebElement loginButton;

public void enterUsername(String username) {
     usernameField.sendKeys(username);
}

public void enterPassword(String password) {
     passwordField.sendKeys(password);  
}

public void clickLogin() {
     loginButton.click();
}

}
```

2. Initialize the page object in your test script:

```java
LoginPage loginPage = new LoginPage(driver);
```

3. Call the methods of the page object:

```java
loginPage.enterUsername("john");
loginPage.enterPassword("pass123");
loginPage.clickLogin();
```

4. If the UI of the login page changes, only the LoginPage class needs to be updated, not the test script.
