# Page Object Model (POM)

### Page Object Model (POM)

Page Object Model (POM) is a design pattern which instruct us to,

1. Treat each page in the our application as Java Objects.
2. Treat each element in the screen like link,input box, check box, button etc., as the member variables of the object. (`WebElement(s)`)
3. All the action that we are going to perform on those elements are methods of that object.

By doing so we can achieve much cleaner, modular, reusable and robust framework.

For example take the Google's home page. In this scenario,

1. The google home page becomes - **`GooglePage.java`**
2. Search input becomes - `private WebElement searchinput;`
3. Typing inside that text box will be like - `public void searchText(String key) {` \
   &#x20;     `searchinput.sendKeys(key + Keys.ENTER);` \
   `}`

```java
public class GooglePage {
	
	@FindBy(name = "q")
	private WebElement searchinput;

	public void searchText(String key) {
		searchinput.sendKeys(key + Keys.ENTER);
	}
}
```

Selenium library has some inbuilt features which we can leverage to achieve POM. One such example is shown in above code `@FindBy` annotation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bharateeshd.gitbook.io/seleniumatoz/framework/building-framework/page-object-model-pom.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
