# List of instructions

## General arguments

All the instructions defined below have a consistent set of arguments. The arguments are as follows.

### `type` <a href="#type" id="type"></a>

* **Type**: `Enum["click", "input", "scroll", "scroll_to_bottom", "wait", "wait_for_element", "fetch_resource"]`
* **Description:** Browser instruction type.

### `timeout_s` <a href="#timeout_s" id="timeout_s"></a>

* **Type**: `int`
* **Description:** How long until action is skipped if not completed in time.
* **Restrictions**: 0 < `timeout_s` <= 60
* **Default value**: 5

### `wait_time_s` <a href="#wait_time_s" id="wait_time_s"></a>

* **Type**: `int`
* **Description:** How long to wait before executing next action.
* **Restrictions**: 0 < `wait_time_s` <= 60
* **Default value**: 0

### `on_error` <a href="#on_error" id="on_error"></a>

* **Type**: `Enum["error", "skip"]`
* **Description:** Indicator what to do with instructions in case this instruction fails:
  * `"error"`: Stops the execution of browser instructions.
  * `"skip"`: Continues with the next instruction.
* **Default value**: `"error"`

#### Example with general arguments

{% code overflow="wrap" %}

```bash
{\"type\": \"wait_for_element\", \"selector\": {\"type\": \"text\", \"value\": \"Load More Items\"},\"timeout_s\": 5, \"wait_time_s\": 2, \"on_error\": \"skip\"}
```

{% endcode %}

## Instructions <a href="#click" id="click"></a>

### `click` <a href="#click" id="click"></a>

* **Description**: Clicks an element and wait a set count of seconds.
* **Args:**
  * `type: str = "click"`
  * `selector: dict`
    * `type: Enum["xpath", "css", "text"]`
    * `value: str`
* **Example**:

{% code overflow="wrap" %}

```bash
{\"type\": \"click\",\"selector\": {\"type\": \"xpath\",\"value\": \"\/\/button\"}}
```

{% endcode %}

### `input` <a href="#input" id="input"></a>

* **Description**: Enters a text into a selected element.
* **Args:**
  * `type: str = "input"`
  * `selector: dict`
    * `type: Enum["xpath", "css", "text"]`
    * `value: str`
  * `value: str`
  * **Example:**

{% code overflow="wrap" %}

```bash
{\"type\": \"input\",\"selector\": {\"type\": \"xpath\",\"value\": \"\/\/input\"},\"value\": \"pizza boxes\"}
```

{% endcode %}

### `scroll` <a href="#scroll" id="scroll"></a>

* **Description**: Scrolls a set count of pixels.
* **Args:**
  * `type: str = "scroll"`
  * `x: int`
  * `y: int`
* **Example:**

```bash
{\"type\": \"scroll\",\"x\": 0,\"y\": 100}
```

### `scroll_to_bottom` <a href="#scroll_to_bottom" id="scroll_to_bottom"></a>

* **Description**: Scrolls to bottom for a set count of seconds.
* **Args:**
  * `type: str = "scroll_to_bottom"`
* **Example**:

```bash
{\"type\": \"scroll_to_bottom\",\"timeout_s\": 10}
```

### `wait` <a href="#wait" id="wait"></a>

* **Description**: Waits a set count of seconds.
* **Args:**
  * `type: str = "wait"`
* **Example**:

```bash
{\"type\": \"wait\",\"wait_time_s\": 2}
```

### `wait_for_element` <a href="#wait_for_element" id="wait_for_element"></a>

* **Description**: Waits for element to load for a set count of seconds.
* **Args:**
  * `type: str = "wait_for_element"`
  * `selector: dict`
    * `type: Enum["xpath", "css", "text"]`
    * `value: str`
  * **Example:**

{% code overflow="wrap" %}

```bash
{\"type\": \"wait_for_element\",\"selector\": {\"type\": \"text\",\"value\": \"Load More Items\"},\"timeout_s\": 5}
```

{% endcode %}

### `fetch_resource` <a href="#fetch_resource" id="fetch_resource"></a>

{% hint style="warning" %}
The `fetch_resource` instruction must be the final instruction in the browser instructions list; any subsequent instructions will not be executed.
{% endhint %}

* **Description**: Fetches the first occurrence of a Fetch/XHR resource matching the set pattern.
* **Args:**
  * `type: str = "fetch_resource"`
  * `filter: str(RegEx expression)`
  * `on_error: Enum["error", "skip"]`
* **Example:**

```bash
{\"type\": \"fetch_resource\",\"filter\": \"\/graphql\/item\/\"}
```

## Instructions' validation

Any inconsistency in regards to instruction format will result in a `400` status code and a corresponding error message.

For example, payload as such:

```bash
[{\"type\": \"unsupported-wait\",\"wait_time_s\": 5}]}]
```

Will result in:

```json
{    
    "errors": {
        "message": "Unsupported action type `unsupported-wait`, choose from 'click,fetch_resource,input,scroll,scroll_to_bottom,wait,wait_for_element'"
    }
}
```
