> ## Documentation Index
> Fetch the complete documentation index at: https://help.decodo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Browser Actions

> Web Scraping API Browser Actions

Scraper APIs support performing a number of browser actions before retrieving a desired result.

## Actions

### `click`

| Name    | Arguments                                              | Description                                                                      |
| ------- | ------------------------------------------------------ | -------------------------------------------------------------------------------- |
| `click` | Selectors: `type`:"xpath"/"css"/"text" `value`: string | Performs a click action on a specified element and waits a set count of seconds. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "click",
              "selector": {
                "type": "xpath",
                "value": "//button"
              }
          }
      ]
  }
  ```
</CodeGroup>

### `input`

| Name    | Arguments                                                                   | Description                                              |
| ------- | --------------------------------------------------------------------------- | -------------------------------------------------------- |
| `input` | Selectors: \*`type`: "xpath"/"css"/"text" \*`value`: string `value`: string | Inserts text into a specified input element on the page. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "input",
              "selector": {
                  "type": "xpath",
                  "value": "//input"
              },
  	"value": "Hello world"	
          }
      ]
  }
  ```
</CodeGroup>

### `scroll`

| Name     | Arguments                 | Description                                                   |
| -------- | ------------------------- | ------------------------------------------------------------- |
| `scroll` | `x`: integer `y`: integer | Scrolls the content of a page a a specified number of pixels. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "scroll",
              "x": "0",
              "y": "300"
          }
      ]
  }
  ```
</CodeGroup>

### `scroll_to_bottom`

| Name               | Arguments            | Description                                        |
| ------------------ | -------------------- | -------------------------------------------------- |
| `scroll_to_bottom` | `timeout_s`: integer | Scrolls down the page for a set amount of seconds. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "scroll_to_bottom",
              "timeout_s": 5
          }
      ]
  }
  ```
</CodeGroup>

### `wait`

| Name   | Arguments              | Description                               |
| ------ | ---------------------- | ----------------------------------------- |
| `wait` | `wait_time_s`: integer | Pauses for a specified number of seconds. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "wait",
              "wait_time_s": 5
          }
      ]
  }
  ```
</CodeGroup>

### `wait_for_element`

| Name               | Arguments                                                                        | Description                                         |
| ------------------ | -------------------------------------------------------------------------------- | --------------------------------------------------- |
| `wait_for_element` | Selectors: \*`type`: "xpath"/"css"/"text" \*`value`: string `timeout_s`: integer | Waits for a specified duration for element to load. |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "wait_for_element",
              "selector": {
                  "type": "css",
                  "value": ".submit-button"
              },
  	"timeout_s": 5
          }
      ]
  }
  ```
</CodeGroup>

### `fetch_resource`

<Warning>
  `fetch_resource` cannot be combined with any other instructions and should be used with separate requests.
</Warning>

| Name             | Arguments                                 | Description                                                                  |
| ---------------- | ----------------------------------------- | ---------------------------------------------------------------------------- |
| `fetch_resource` | `filter`: regex `on_error`:"error"/"skip" | Retrieves the first Fetch or XHR resource that matches the specified pattern |

**Example:**

<CodeGroup>
  ```json JSON theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "fetch_resource",
              "filter": "https://api.example.com/products/*",          
              "on_error": "error"
          }
      ]
  }
  ```
</CodeGroup>

## General Arguments

Arguments available for all actions above

### `type`

| Name   | Description                 |
| ------ | --------------------------- |
| `type` | Type of browser action used |

### `timeout_s`

| Name        | Description                                                                              |
| ----------- | ---------------------------------------------------------------------------------------- |
| `timeout_s` | How much time in seconds to wait at max until the execution of the action is terminated. |

### `wait_time_s`

| Name          | Description                                                       |
| ------------- | ----------------------------------------------------------------- |
| `wait_time_s` | How much time in seconds to use explicitly to execute the action. |

### `on_error`

| Name       | Description                                                                                                                                   |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `on_error` | Indicates what to do with actions in case they fail: "error": Stops the execution of browser actions. "skip": Continues with the next action. |

## Fetching a Network Request

If a website populates content by fetching a `JSON` object, you can scrape just the network request and thus avoid having to deal with `HTML` altogether. To do this, you can use the `fetch_resource` browser action, as shown below.

<Warning>
  `fetch_resource` cannot be combined with any other instructions and can only be used with separate requests.
</Warning>

For example, when loading yahoo.com and opening the Network tab, we can see an `exp.json` file being loaded:

<Frame>
  <img src="https://mintcdn.com/decodo/HeowWjVaMvMCJRIK/images/docs/539e0b0-how_to_use_spoons_2024-05-10_at_13.02.09.png?fit=max&auto=format&n=HeowWjVaMvMCJRIK&q=85&s=9e768d6d99a4e5007241ba7cc8a0c7ba" alt="" width="1432" height="1171" data-path="images/docs/539e0b0-how_to_use_spoons_2024-05-10_at_13.02.09.png" />
</Frame>

If you wish to scrape just the contents of this request, you can use the `fetch_resource` browser action. Note that `filter` is a regular expression that matches the filename:

<CodeGroup>
  ```json Payload theme={null}
  {
      "target": "universal",
      "url": "https://www.yahoo.com/",
      "browser_actions": [
          {
              "type": "fetch_resource",
              "filter": "/ybar/exp"
          }
      ]
  }
  ```
</CodeGroup>

Results:

<CodeGroup>
  ```json Payload theme={null}
  {
      "results": [
          {
              "content": "{\n    \"expCount\":5,\n    \"selection\":\"individual\",\n ... }",
              "status_code": 200,
              "url": "https://example.com/api/product/1",
              "task_id": "7131940420107377665",
              "created_at": "2023-11-19 09:46:41",
              "updated_at": "2023-11-19 09:47:08"
          }
      ]
  }
  ```
</CodeGroup>

***

<Columns cols={2}>
  <Card title="Support" href="https://direct.lc.chat/12092754" cta="Let's chat!">
    Need help or just want to say hello? Our support is available 24/7. \
    You can also reach us anytime via email at [support@decodo.com](mailto:support@decodo.com).
  </Card>

  <Card title="Feedback" href="mailto:feedback@decodo.com" cta="Share feedback">
    Can't find what you're looking for? Request an article! \
    Have feedback? Share your thoughts on how we can improve.
  </Card>
</Columns>
