# Rendering Instruction Set

The Render Instruction Set is a set of instructions that can be used to instruct the browser to execute specific actions during page rendering. By combining these instructions, you can execute complex operations such as <mark style="background-color:green;">completing a search form</mark> or <mark style="background-color:orange;">scrolling through an endlessly scrolling page</mark>. This capability enables efficient automation of dynamic web content interactions.

### How to use

To send an instruction set to the browser, you send a JSON object to the API <mark style="background-color:red;">as a header</mark>, along with any other necessary parameters, including the "render=true" parameter.&#x20;

In the following example, we enter a search term into a form, click the search icon, and then wait for the search results to load.

<div data-full-width="false"><figure><img src="/files/UJJIDaRLXA4sidpHgIfw" alt=""><figcaption></figcaption></figure></div>

```json
[
  {
    "type": "input",
    "selector": { "type": "css", "value": "#searchInput" },
    "value": "cowboy boots"
  },
  {
    "type": "click",
    "selector": {
      "type": "css",
      "value": "#search-form button[type=\"submit\"]"
    }
  },
  {
    "type": "wait_for_selector",
    "selector": { "type": "css", "value": "#content" }
  }
]
```

To send the above instruction set to our API endpoint, it must be formatted as a single string and passed <mark style="background-color:red;">as a header</mark>.&#x20;

{% hint style="success" %}
Reducing the number of actions you instruct the API to perform gives you a higher chance of getting a successful response. Clicking through multiple pages adds to the total latency of the request, which can lead to timeouts. For best performance, limit the instruction set down to 3-4 actions.
{% endhint %}

{% hint style="danger" %}
Please note that the "<mark style="background-color:red;">x-sapi-</mark>" prefix should be used on each header to prevent collisions with headers used by target sites.
{% endhint %}

* **API REQUEST**

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request GET \
  --url 'https://api.scraperapi.com?url=https://www.wikipedia.org' \
  --header 'x-sapi-api_key: API_KEY' \
  --header 'x-sapi-render: true' \
  --header 'x-sapi-instruction_set: [{"type":"input","selector":{"type":"css","value":"#searchInput"},"value":"cowboy boots"},{"type":"click","selector":{"type":"css","value":"#search-form button[type=\"submit\"]"}},{"type":"wait_for_selector","selector":{"type":"css","value":"#content"}}]'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.scraperapi.com"

params = {
    "url": "https://www.wikipedia.org"
}

headers = {
    # Replace the value for api_key with your actual API Key.
    "x-sapi-api_key": "API_KEY",
    "x-sapi-render": "true",
    "x-sapi-instruction_set": (
        '[{"type":"input","selector":{"type":"css","value":"#searchInput"},"value":"cowboy boots"},'
        '{"type":"click","selector":{"type":"css","value":"#search-form button[type=\\"submit\\"]"}},'
        '{"type":"wait_for_selector","selector":{"type":"css","value":"#content"}}]'
    )
}
response = requests.get(url, params=params, headers=headers)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from "node-fetch";

const url = new URL("https://api.scraperapi.com");
url.searchParams.append("url", "https://www.wikipedia.org");

const instructionSet = [
  {
    type: "input",
    selector: { type: "css", value: "#searchInput" },
    value: "cowboy boots"
  },
  {
    type: "click",
    selector: { type: "css", value: "#search-form button[type=\"submit\"]" }
  },
  {
    type: "wait_for_selector",
    selector: { type: "css", value: "#content" }
  }
];

const response = await fetch(url, {
  method: "GET",
  headers: {
    // Replace the value for api_key with your actual API Key.
    "x-sapi-api_key": "API_KEY",
    "x-sapi-render": "true",
    "x-sapi-instruction_set": JSON.stringify(instructionSet)
  }
});

const body = await response.text();
console.log(body);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = "https://api.scraperapi.com?url=https://www.wikipedia.org";

$instructionSet = json_encode([
    [
        "type" => "input",
        "selector" => [
            "type" => "css",
            "value" => "#searchInput"
        ],
        "value" => "cowboy boots"
    ],
    [
        "type" => "click",
        "selector" => [
            "type" => "css",
            "value" => "#search-form button[type=\"submit\"]"
        ]
    ],
    [
        "type" => "wait_for_selector",
        "selector" => [
            "type" => "css",
            "value" => "#content"
        ]
    ]
]);

$headers = [
    // Replace the value for api_key with your actual API Key.
    "x-sapi-api_key: API_KEY",
    "x-sapi-render: true",
    "x-sapi-instruction_set: " . $instructionSet
];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

$response = curl_exec($ch);

curl_close($ch);

echo $response;
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'

params = {
  url: "https://www.wikipedia.org"
}

uri = URI("https://api.scraperapi.com")
uri.query = URI.encode_www_form(params)

instruction_set = [
  {
    type: "input",
    selector: { type: "css", value: "#searchInput" },
    value: "cowboy boots"
  },
  {
    type: "click",
    selector: { type: "css", value: "#search-form button[type=\"submit\"]" }
  },
  {
    type: "wait_for_selector",
    selector: { type: "css", value: "#content" }
  }
]

req = Net::HTTP::Get.new(uri)
# Replace the value for api_key with your actual API Key.
req["x-sapi-api_key"] = "API_KEY"
req["x-sapi-render"] = "true"
req["x-sapi-instruction_set"] = instruction_set.to_json

http = Net::HTTP.new(uri.hostname, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

response = http.request(req)
puts response.body
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws Exception {
        // Replace the value for api_key with your actual API Key.
        String apiKey = "API_KEY";
        String targetUrl = "https://www.wikipedia.org";

        String instructionSet =
            "[{\"type\":\"input\",\"selector\":{\"type\":\"css\",\"value\":\"#searchInput\"},\"value\":\"cowboy boots\"}," +
            "{\"type\":\"click\",\"selector\":{\"type\":\"css\",\"value\":\"#search-form button[type=\\\"submit\\\"]\"}}," +
            "{\"type\":\"wait_for_selector\",\"selector\":{\"type\":\"css\",\"value\":\"#content\"}}]";

        String scraperApiUrl =
            "https://api.scraperapi.com?url=" +
            URLEncoder.encode(targetUrl, StandardCharsets.UTF_8);

        HttpClient client = HttpClient.newHttpClient();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(scraperApiUrl))
                .GET()
                .header("x-sapi-api_key", apiKey)
                .header("x-sapi-render", "true")
                .header("x-sapi-instruction_set", instructionSet)
                .build();

        HttpResponse<String> response =
                client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println(response.body());
    }
}
```

{% endtab %}
{% endtabs %}

* **ASYNC REQUEST**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST \
  --url 'https://async.scraperapi.com/jobs' \
  -H 'Content-Type: application/json' \
  -d '{
    "apiKey": "API_KEY",
    "url": "https://www.wikipedia.org",
    "headers": {
      "x-sapi-render": "true",
      "x-sapi-instruction_set": "[{\"type\":\"input\",\"selector\":{\"type\":\"css\",\"value\":\"#searchInput\"},\"value\":\"cowboy boots\"},{\"type\":\"click\",\"selector\":{\"type\":\"css\",\"value\":\"#search-form button[type=\\\"submit\\\"]\"}},{\"type\":\"wait_for_selector\",\"selector\":{\"type\":\"css\",\"value\":\"#content\"}}]"
    }
  }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://async.scraperapi.com/jobs"

payload = {
    # Replace the value for api_key with your actual API Key.
    "apiKey": "API_KEY",
    "url": "https://www.wikipedia.org",
    "headers": {
        "x-sapi-render": "true",
        "x-sapi-instruction_set": json.dumps([
            {
                "type": "input",
                "selector": {"type": "css", "value": "#searchInput"},
                "value": "cowboy boots"
            },
            {
                "type": "click",
                "selector": {
                    "type": "css",
                    "value": "#search-form button[type=\"submit\"]"
                }
            },
            {
                "type": "wait_for_selector",
                "selector": {"type": "css", "value": "#content"}
            }
        ])
    }
}

response = requests.post(url, json=payload)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import axios from "axios";

const url = "https://async.scraperapi.com/jobs";

const payload = {
  // Replace the value for api_key with your actual API Key.
  apiKey: "API_KEY",
  url: "https://www.wikipedia.org",
  headers: {
    "x-sapi-render": "true",
    "x-sapi-instruction_set": JSON.stringify([
      {
        type: "input",
        selector: { type: "css", value: "#searchInput" },
        value: "cowboy boots"
      },
      {
        type: "click",
        selector: {
          type: "css",
          value: "#search-form button[type=\"submit\"]"
        }
      },
      {
        type: "wait_for_selector",
        selector: { type: "css", value: "#content" }
      }
    ])
  }
};

axios.post(url, payload, {
  headers: {
    "Content-Type": "application/json"
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error(error.response?.data || error.message);
});
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$payload = json_encode([
    // Replace the value for api_key with your actual API Key.
    "apiKey" => "API_KEY",
    "url"    => "https://www.wikipedia.org",
    "headers" => [
        "x-sapi-render" => "true",
        "x-sapi-instruction_set" => json_encode([
            [
                "type" => "input",
                "selector" => [
                    "type" => "css",
                    "value" => "#searchInput"
                ],
                "value" => "cowboy boots"
            ],
            [
                "type" => "click",
                "selector" => [
                    "type" => "css",
                    "value" => "#search-form button[type=\"submit\"]"
                ]
            ],
            [
                "type" => "wait_for_selector",
                "selector" => [
                    "type" => "css",
                    "value" => "#content"
                ]
            ]
        ])
    ]
]);

$ch = curl_init("https://async.scraperapi.com/jobs");

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'

uri = URI('https://async.scraperapi.com/jobs')

payload = {
  # Replace the value for api_key with your actual API Key.
  "apiKey" => "API_KEY",
  "url" => "https://www.wikipedia.org",
  "headers" => {
    "x-sapi-render" => "true",
    "x-sapi-instruction_set" => [
      {
        "type" => "input",
        "selector" => { "type" => "css", "value" => "#searchInput" },
        "value" => "cowboy boots"
      },
      {
        "type" => "click",
        "selector" => {
          "type" => "css",
          "value" => "#search-form button[type=\"submit\"]"
        }
      },
      {
        "type" => "wait_for_selector",
        "selector" => { "type" => "css", "value" => "#content" }
      }
    ].to_json
  }
}

response = Net::HTTP.post(
  uri,
  payload.to_json,
  "Content-Type" => "application/json"
)

puts response.body
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://async.scraperapi.com/jobs");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoOutput(true);

            String payload =
                "{"
              // Replace the value for api_key with your actual API Key.
              + "\"apiKey\":\"API_KEY\","
              + "\"url\":\"https://www.wikipedia.org\","
              + "\"headers\":{"
              +   "\"x-sapi-render\":\"true\","
              +   "\"x-sapi-instruction_set\":\""
              +     "[{\\\"type\\\":\\\"input\\\",\\\"selector\\\":{\\\"type\\\":\\\"css\\\",\\\"value\\\":\\\"#searchInput\\\"},\\\"value\\\":\\\"cowboy boots\\\"},"
              +     "{\\\"type\\\":\\\"click\\\",\\\"selector\\\":{\\\"type\\\":\\\"css\\\",\\\"value\\\":\\\"#search-form button[type=\\\\\\\"submit\\\\\\\"]\\\"}},"
              +     "{\\\"type\\\":\\\"wait_for_selector\\\",\\\"selector\\\":{\\\"type\\\":\\\"css\\\",\\\"value\\\":\\\"#content\\\"}}]"
              +   "\""
              + "}"
              + "}";

            try (OutputStream os = conn.getOutputStream()) {
                os.write(payload.getBytes(StandardCharsets.UTF_8));
            }

            try (BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                        conn.getResponseCode() >= 200 && conn.getResponseCode() < 300
                            ? conn.getInputStream()
                            : conn.getErrorStream()
                    )
            )) {
                StringBuilder response = new StringBuilder();
                String line;
                while ((line = in.readLine()) != null) {
                    response.append(line);
                }
                System.out.println(response.toString());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

* **PROXY MODE**

{% tabs %}
{% tab title="cURL" %}

```bash
curl \
  --url 'https://www.wikipedia.org' \
  --proxy 'http://scraperapi:API_KEY@proxy-server.scraperapi.com:8001' \
  --header 'x-sapi-render: true' \
  --header 'x-sapi-instruction_set: [{"type":"input","selector":{"type":"css","value":"#searchInput"},"value":"cowboy boots"},{"type":"click","selector":{"type":"css","value":"#search-form button[type=\"submit\"]"}},{"type":"wait_for_selector","selector":{"type":"css","value":"#content"}}]' \
  -k
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://www.wikipedia.org"
# Replace the value for api_key with your actual API Key.
proxy = "http://scraperapi:API_KEY@proxy-server.scraperapi.com:8001"

proxies = {
    "http": proxy,
    "https": proxy,
}

headers = {
    "x-sapi-render": "true",
    "x-sapi-instruction_set": json.dumps([
        {
            "type": "input",
            "selector": {"type": "css", "value": "#searchInput"},
            "value": "cowboy boots"
        },
        {
            "type": "click",
            "selector": {
                "type": "css",
                "value": "#search-form button[type=\"submit\"]"
            }
        },
        {
            "type": "wait_for_selector",
            "selector": {"type": "css", "value": "#content"}
        }
    ])
}

response = requests.get(
    url,
    headers=headers,
    proxies=proxies,
    verify=False
)

print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import axios from 'axios';
import https from 'https';

const url = 'https://www.wikipedia.org';
const agent = new https.Agent({ rejectUnauthorized: false });

axios.get(url, {
  headers: {
    'x-sapi-render': 'true',
    'x-sapi-instruction_set': JSON.stringify([
      {
        type: 'input',
        selector: { type: 'css', value: '#searchInput' },
        value: 'cowboy boots'
      },
      {
        type: 'click',
        selector: {
          type: 'css',
          value: '#search-form button[type="submit"]'
        }
      },
      {
        type: 'wait_for_selector',
        selector: { type: 'css', value: '#content' }
      }
    ])
  },
  proxy: {
    host: 'proxy-server.scraperapi.com',
    port: 8001,
    auth: {
      username: 'scraperapi',
      // Replace the value for password with your actual API Key.
      password: 'API_KEY'
    },
    protocol: 'http'
  },
  httpsAgent: agent
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error(error.response?.data || error.message);
});
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$instructionSet = json_encode([
    [
        "type" => "input",
        "selector" => [
            "type" => "css",
            "value" => "#searchInput"
        ],
        "value" => "cowboy boots"
    ],
    [
        "type" => "click",
        "selector" => [
            "type" => "css",
            "value" => "#search-form button[type=\"submit\"]"
        ]
    ],
    [
        "type" => "wait_for_selector",
        "selector" => [
            "type" => "css",
            "value" => "#content"
        ]
    ]
]);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.wikipedia.org");
curl_setopt(
    $ch,
    CURLOPT_PROXY,
    // Replace the value for api_key with your actual API Key.
    "http://scraperapi:API_KEY@proxy-server.scraperapi.com:8001"
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "x-sapi-render: true",
    "x-sapi-instruction_set: " . $instructionSet
]);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo "Curl error: " . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'httparty'
require 'json'

HTTParty::Basement.default_options.update(verify: false)

instruction_set = [
  {
    "type" => "input",
    "selector" => { "type" => "css", "value" => "#searchInput" },
    "value" => "cowboy boots"
  },
  {
    "type" => "click",
    "selector" => {
      "type" => "css",
      "value" => "#search-form button[type=\"submit\"]"
    }
  },
  {
    "type" => "wait_for_selector",
    "selector" => { "type" => "css", "value" => "#content" }
  }
].to_json

response = HTTParty.get('https://www.wikipedia.org', {
  http_proxyaddr: "proxy-server.scraperapi.com",
  http_proxyport: 8001,
  http_proxyuser: "scraperapi",
  # Replace the value for http_proxypass with your actual API Key.
  http_proxypass: "API_KEY",
  headers: {
    "x-sapi-render" => "true",
    "x-sapi-instruction_set" => instruction_set
  }
})

puts response.body
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.*;
import java.net.*;
import javax.net.ssl.*;
import java.security.cert.X509Certificate;

public class Main {
    public static void main(String[] args) {
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
            sc.init(null, new TrustManager[]{
                new X509TrustManager() {
                    public X509Certificate[] getAcceptedIssuers() { return null; }
                    public void checkClientTrusted(X509Certificate[] certs, String authType) {}
                    public void checkServerTrusted(X509Certificate[] certs, String authType) {}
                }
            }, new java.security.SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true);

            String apiKey = "API_KEY"; // Replace the value for api_key with your actual API Key.
            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(
                        "scraperapi", apiKey.toCharArray()
                    );
                }
            });

            System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
            System.setProperty("https.proxyHost", "proxy-server.scraperapi.com");
            System.setProperty("https.proxyPort", "8001");
            
            String instructionSet =
                "[{\"type\":\"input\",\"selector\":{\"type\":\"css\",\"value\":\"#searchInput\"},\"value\":\"cowboy boots\"}," +
                "{\"type\":\"click\",\"selector\":{\"type\":\"css\",\"value\":\"#search-form button[type=\\\"submit\\\"]\"}}," +
                "{\"type\":\"wait_for_selector\",\"selector\":{\"type\":\"css\",\"value\":\"#content\"}}]";

            HttpsURLConnection conn =
                (HttpsURLConnection) new URL("https://www.wikipedia.org/").openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("x-sapi-render", "true");
            conn.setRequestProperty("x-sapi-instruction_set", instructionSet);

            BufferedReader in;
            if (conn.getResponseCode() >= 400) {
                in = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
            } else {
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            }

            StringBuilder resp = new StringBuilder();
            String line;
            while ((line = in.readLine()) != null) {
                resp.append(line).append("\n");
            }
            in.close();

            System.out.println(resp.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Supported Instructions

Browser instructions are organized as an array of objects within the instruction set, each with a specific structure. Below are the various instructions and the corresponding data they require

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td>Click</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#click">/pages/y5Th18eZsMFJ3Yh5e3ws#click</a></td></tr><tr><td>Input</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#input">/pages/y5Th18eZsMFJ3Yh5e3ws#input</a></td></tr><tr><td>Loop</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#loop">/pages/y5Th18eZsMFJ3Yh5e3ws#loop</a></td></tr><tr><td>Scroll</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#scroll">/pages/y5Th18eZsMFJ3Yh5e3ws#scroll</a></td></tr><tr><td>Wait</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#wait">/pages/y5Th18eZsMFJ3Yh5e3ws#wait</a></td></tr><tr><td>Wait for Event</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#wait_for_event">/pages/y5Th18eZsMFJ3Yh5e3ws#wait_for_event</a></td></tr><tr><td>Wait for Selector</td><td></td><td><a href="/pages/y5Th18eZsMFJ3Yh5e3ws#wait_for_selector">/pages/y5Th18eZsMFJ3Yh5e3ws#wait_for_selector</a></td></tr></tbody></table>

#### <mark style="background-color:orange;">Click</mark>

Click on an element on the page.

|           |                                                                                                                                                              |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Args`    | <p>type: str = "click"<br>selector: dict<br>    type: Enum\["xpath", "css", "text"]<br>    value: str<br>timeout: int (optional)</p>                         |
| `Example` | <p>\[{</p><p>    "type": "click",<br>    "selector": {<br>        "type": "css",<br>        "value": "#search-form button\[type="submit"]"<br>   }<br>}]</p> |

#### <mark style="background-color:orange;">Input</mark>

Enter a value into an input field on the page.

|           |                                                                                                                                                                         |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Args`    | <p>type: str = "input"<br>selector: dict<br>    type: Enum\["xpath", "css", "text"]<br>    value: str<br>value: str<br>timeout: int (optional)</p>                      |
| `Example` | <p>\[{</p><p>   "type": "input",<br>    "selector": {<br>        "type": "css",<br>        "value": "#searchInput"<br>     },<br>     "value": "cowboy boots"<br>}]</p> |

#### <mark style="background-color:orange;">Loop</mark>

Execute a set of instructions in a loop a specified number of times by using the loop instruction with a sequence of standard instructions in the “instructions” argument.&#x20;

Note that nesting loops isn't supported, so you can't create a “loop” instruction inside another “loop” instruction. This method is effective for automating actions on web pages with infinitely scrolling content, such as loading multiple pages of results by scrolling to the bottom of the page and waiting for additional content to load.

|           |                                                                                                                                                                                                                                                                                                                               |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Args`    | <p>type: str="loop"<br>for: int<br>instructions: array</p>                                                                                                                                                                                                                                                                    |
| `Example` | <p>\[{</p><p>    "type": "loop",<br>    "for": 3,<br>    "instructions": \[<br>         {<br>             "type": "scroll",<br>             "direction": "y",<br>             "value": "bottom"<br>          },<br>          {<br>             "type": "wait",<br>              "value": 5<br>          }<br>     ]<br>}]</p> |

#### <mark style="background-color:orange;">Scroll</mark>

Scroll the page in the **X (horizontal)** or **Y (vertical)** direction, by a given number of pixels or to the top or bottom of the page. You can also scroll to a given element by adding a selector.

|           |                                                                                                                                                                                                                                                                                          |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Args`    | <p>type: str = "scroll"</p><p></p><p>direction: Enum\["x", "y"]</p><p>      value: int or <br>      Enum\["bottom", "top"]</p><p></p><p>selector: dict  <br>     type: Enum\["xpath", "css", "text"] <br>      value: str<br></p>                                                        |
| `Example` | <p>\[{<br>    "type": "scroll",<br>    "direction": "y",<br>    "value": "bottom"<br>}]<br></p><p><br><br>\[{ </p><p>      "type": "scroll", </p><p>      "selector": {</p><p>           "type":"css",</p><p>           "value":"#payment-container" </p><p>             } </p><p>}]</p> |

#### <mark style="background-color:orange;">Wait</mark>

Waits for a given number of seconds to elapse.

| Description |                                                            |
| ----------- | ---------------------------------------------------------- |
| `Args`      | <p>type: str = "wait"<br>value: int<br></p>                |
| `Example`   | <p>\[{<br>    "type": "wait",<br>    "value": 10<br>}]</p> |

#### <mark style="background-color:orange;">Wait\_for\_event</mark>

Waits for an event to occur within the browser.&#x20;

|           |                                                                                                                                                                                                                                                                                                                                                                 |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Args`    | <p>type: str = "wait\_for\_event"<br>event: Enum\["domcontentloaded", "load", "navigation", "networkidle", "stabilize"]<br></p><p>timeout: int (in seconds, optional)<br>seconds:int (in seconds, optional in combination with stabilize event)</p><p></p>                                                                                                      |
| `Example` | <p>\[{<br>    "type": "wait\_for\_event",<br>    "event": "networkidle",<br>    "timeout": 10<br>}] </p><p></p><p></p><p>\[{<br>"type": "wait\_for\_event",<br>"event": "stabilize",<br>"seconds": 10<br>}]</p>                                                                                                                                                 |
| `Values`  | <p></p><ul><li><strong>domcontentloaded</strong> = initial HTML loaded</li><li><strong>load</strong> = full page load</li><li><strong>navigation</strong> = page navigation</li><li><strong>networkidle</strong> = network requests stopped</li><li><strong>stabilize</strong> = page reaches steady state (default is 5 seconds, max. is 30 seconds)</li></ul> |

#### <mark style="background-color:orange;">Wait\_for\_selector</mark>

Waits for an element to appear on the page. Takes a 'value' argument that instructs the rendering engine to wait for a specified number of seconds for the element to appear.

|           |                                                                                                                                                                       |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Args`    | <p>type: str = "wait\_for\_selector"<br>selector: dict<br>    type: Enum\["xpath", "css", "text"]<br>    value: str<br>timeout: int (optional)<br></p>                |
| `Example` | <p>\[{<br>    "type": "wait\_for\_selector",<br>    "selector": {<br>        "type": "css",<br>        "value": "#content"</p><p>    },<br>    "timeout": 5<br>}]</p> |


---

# 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.scraperapi.com/javascript-rendering/rendering-instruction-set.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.
