Introduction
Quite often, you need to do something with a website before getting a page source or a screenshot.
Our JS instructions feature is designed specifically for this purpose.
Usage
To interact with the webpage after it is fully loaded set js_instructions field. Example:
{
"js_instructions": [
{ "click": "#myButton" },
{ "wait": 3000 },
{ "type": ["#inputfield", "superman12"] },
{ "check": "#myCheckbox" },
{ "click": "#myButton2" },
{ "wait": 2000 }
]
}
If your selector starts with a forward slash / - it will be treated as XPath selector. Otherwise — as CSS selector.
Stop on failure
By default, the browser is not running your actions in a Strict mode. So if one of them fails or is invalid - the browser ignores the error and
continues executing the remaining actions.
If you want to enable Strict mode and stop all the instructions once one fails - you can set field stop_instructions_on_fail to true.
Default value is false.
{
"stop_instructions_on_fail": true
}
Available actions
| Action | Value |
|---|
| click | "selector" |
| check | "selector" |
| uncheck | "selector" |
| wait | integer |
| scroll_to | "top" or "bottom" |
| type | ["selector", "value"] |
| select | ["selector", "option value"] |
| infinite_scroll | {"max_scrolls": integer, "wait": integer, "click": "selector"} |
| solve_cf_captcha | true |
| evaluate | "your js code" |
Click
If you need the browser to click some element on the webpage, you can use click instruction:
Check
Use it to click on a checkbox:
{ "check": "#myCheckbox" }
Uncheck
Use it to uncheck a checkbox:
{ "uncheck": "#myCheckbox" }
Wait
Wait for amount of time, defined in milliseconds:
The total amount of time you can wait using wait and infinite_scroll.wait is 120000 (120 seconds), while the maximum value for a single wait/infinite_scroll.wait is 30000 (30 seconds)
Scroll the webpage to bottom or to top.
Available values: "bottom", "top"
{ "scroll_to": "bottom" }
Type
Type in your value in some input, defined by "selector"
{ "type": ["#inputUsername", "superman12"] }
Select
Select option from select HTML element by option value
{ "type": [".countrySelector", "us"] }
Use this action to scroll the page down multiple times.
The value must be an object with the following fields:
max_scrolls - how many times the scroll must be executed. Integer between 1 and 10000. Required.
wait - Wait for amount of time, defined in milliseconds. Maximum value - 30000 (30 seconds). Optional.
click - Click some element on the webpage after scrolling. Value — CSS or XPath selector. Optional.
{
"infinite_scroll": {
"max_scrolls": 10,
"wait": 3000,
"click": ".loadMoreButton"
}
}
The total amount of time you can wait using wait and infinite_scroll.wait is 120000 (120 seconds), while the maximum value for a single wait/infinite_scroll.wait is 30000 (30 seconds)
Solve Cloudflare Captcha
If you have a Cloudflare Captcha on a webpage, for example, on a form, you can use this action to solve the captcha.
Cloudflare captchas are located in HTML iframes,
so you need only to include this action to js_instructions parameter with value true:
{ "solve_cf_captcha": true }
It is highly recommended to use this action only with our Stealth proxies.
Evaluate
More complex cases might require more flexibility. So ScrapexLabs allows you to run custom JavaScript code.
{ "evaluate": "console.log('hello')" }