# page\_object\_locators

### Introduction

This guide provides detailed instructions on how to set up and use page object locators for web automation in Scriptless Automation. It includes the structure for storing locators, how to define them, and how to use them in web templates.

### Directory Structure

The locators for web pages should be stored in a dedicated directory within your test data folder. The recommended structure is as follows:

```
project
   └── test_data
       └── web
           └── page_object_locators
               └── gmail.properties
```

### Defining Locators

Locators should be defined in properties files. Each property represents a locator with its unique identifier and the type of selector used.

Locator syntax should be follow as below

```
elementName = SelectorType -> selector
```

#### **Example: `gmail.properties`**

```properties
# Locator definitions for Gmail
email = XPATH -> //*[@id="identifierId"]
```

In this example:

* `email` is the name of the element i.e. `elementName`.
* `XPATH` is the type of selector used to locate the element i.e. `selectorType`.
* `//*[@id="identifierId"]` is the actual XPath expression to locate the element i.e. `selector`.
* `elementName` and `SelectorType` define another locator with a generic name and type.

### Using Locators in Web Templates

Web templates use these locators to perform actions on the web elements. Each action is defined in a CSV file that specifies the page name, wait type, scroll type, element name, action to be performed, value to be sent, validation, and validation type.

#### **Example: Web Template**

```csv
csvCopy codePAGE_NAME,WAIT_TYPE,SCROLL_TYPE,ELEMENT_NAME,ACTIONS,SEND_KEYS,VALIDATION,VALIDATION_TYPE
gmail,NONE,NONE,NONE,LOAD_URL,https://www.gmail.com/,NONE,NONE
gmail,VISIBILITY,NONE,email,SEND_KEYS,john depth,NONE,NONE
```

In this example:

* The first row loads the Gmail URL.
* The second row waits for the visibility of the `email` element and then sends the text `john depth` to it.

### Supported Selector Types

The following types of selectors are supported:

* `ID`: Selects elements based on their unique ID attribute.
* `NAME`: Selects elements based on their name attribute.
* `CLASS_NAME`: Selects elements based on their class attribute.
* `TAG_NAME`: Selects elements based on their tag name.
* `LINK_TEXT`: Selects anchor elements with the exact visible text.
* `PARTIAL_LINK_TEXT`: Selects anchor elements containing the specified partial text.
* `XPATH`: Selects elements using XPath expressions.
* `CSS`: Selects elements using CSS selectors.

<br>


---

# 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://docs.precisiontestautomation.in/scriptlessautomation/automation-platforms/scriptlessweb-automation/page_object_locators.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.
