Logic & Branching
Conditional and random-choice actions that control script flow. These let you handle different page states, variation testing, and multi-path workflows without writing separate scripts.
if / branch / if_else
Conditional branching. Checks a detect condition (selector / text / URL on the page) and/or a variable comparison, then runs then actions if true or else actions if false. All three names are identical aliases.
Detect Condition
The detect object uses the same format as page-level detection rules. You can check for selectors, visible text, URL patterns, and frame URLs.
| Param | Type | Description |
|---|---|---|
| detectoptional | object | Detection block: selector, text, url_contains, frame_url_contains. Same format as page detect. |
| detect.modeoptional | string | "any" (default for if) or "all". How multiple signals combine. |
| timeoutoptional | number | Ms to wait for detect to become true. Default: 0 (check once, no waiting). |
| poll_msoptional | number | Polling interval when timeout > 0. Default: 200ms. |
Variable Condition
Compare a variable captured by read (or a sheet column) against a value. Can be combined with a detect condition.
| Param | Type | Description |
|---|---|---|
| varoptional | string | Variable name (from read) or {{TEMPLATE}} to compare. |
| equalsoptional | string | True if var equals this value. |
| not_equalsoptional | string | True if var does not equal this value. |
| containsoptional | string | True if var contains this substring. |
| not_containsoptional | string | True if var does not contain this substring. |
| matchesoptional | string | True if var matches this regex pattern. |
| not_emptyoptional | boolean | True if var is not empty (has non-whitespace content). |
| emptyoptional | boolean | True if var is empty or whitespace-only. |
| ignore_caseoptional | boolean | Case-insensitive comparison. Default: false. |
Combining & Branching
| Param | Type | Description |
|---|---|---|
| matchoptional | string | "all" (AND, default) or "any" (OR) — how detect + var results combine. |
| negateoptional | boolean | Invert the final result. Default: false. |
| thenrequired | array | Actions to run if the condition is true. |
| elseoptional | array | Actions to run if the condition is false. Alias: otherwise. |
// Selector-based condition
{
"type": "if",
"detect": { "selector": "#error-message" },
"then": [
{ "type": "click", "selector": "#retry-btn" }
],
"else": [
{ "type": "click", "selector": "#continue" }
]
}// Text-based condition
{
"type": "branch",
"detect": { "text": "Already registered" },
"then": [
{ "type": "sheet_status", "value": "duplicate" },
{ "type": "exit_script" }
]
}// Variable condition — compare a value captured by read
{
"type": "if",
"var": "STATE",
"equals": "California",
"then": [
{ "type": "select", "selector": "#region", "value": "West" }
],
"else": [
{ "type": "select", "selector": "#region", "value": "East" }
]
}// Combined detect + variable with timeout
{
"type": "if",
"detect": { "selector": "#otp-field" },
"var": "OTP_CODE",
"not_empty": true,
"match": "all",
"timeout": 5000,
"then": [
{ "type": "type", "selector": "#otp", "value": "{{OTP_CODE}}" },
{ "type": "click", "selector": "#verify" }
],
"else": [
{ "type": "click", "selector": "#skip-otp" }
]
}// URL-based condition with negate
{
"type": "if",
"detect": { "url_contains": "thank-you" },
"negate": true,
"then": [
{ "type": "sheet_status", "value": "failure" },
{ "type": "exit_script" }
]
}one_of
Random choice — picks one branch from a list of action arrays and runs it. The chosen branch is pinned on retry: if the step retries, it re-runs the same branch instead of picking a new one (prevents half-executed branch A followed by branch B).
| Param | Type | Description |
|---|---|---|
| choicesrequired | array | Array of action arrays. Each inner array is one possible branch. Single actions are auto-wrapped. |
| pickoptional | string | Selection strategy. Default: "random". |
| repick_on_retryoptional | boolean | If true, re-randomize on step retry instead of reusing the pinned branch. Default: false. |
{
"type": "one_of",
"choices": [
[{ "type": "click", "selector": "#plan-basic" }],
[{ "type": "click", "selector": "#plan-premium" }],
[{ "type": "click", "selector": "#plan-family" }]
]
}// Multi-action branches with repick on retry
{
"type": "one_of",
"repick_on_retry": true,
"choices": [
[
{ "type": "click", "selector": "#option-a" },
{ "type": "type", "selector": "#reason", "value": "Best price" }
],
[
{ "type": "click", "selector": "#option-b" },
{ "type": "type", "selector": "#reason", "value": "Great quality" }
]
]
}read
Read a value from a page element and store it in a variable. The variable can be used later with {{VAR_NAME}} syntax in any action's value field, or checked in an if condition.
| Param | Type | Description |
|---|---|---|
| selectorrequired | string | array | CSS selector or array of selectors for the element to read from. |
| asrequired | string | Variable name to store the result. Must start with a letter or underscore. Use as {{VAR_NAME}} in later actions. Alias: var. |
| whatoptional | string | "text" (default) — visible text; "value" — input value or checkbox state; "attribute" — a specific HTML attribute. |
| attributeoptional | string | Required when what is "attribute". The HTML attribute name to read (e.g. "href", "data-id"). Alias: attr. |
| indexoptional | number | Which visible match to read from (0 = first). Default: 0. |
// Read visible text
{ "type": "read", "selector": "#confirmation-number", "as": "CONF_NUM", "what": "text" }
111
{ "type": "sheet_comment", "value": "Confirmation: {{CONF_NUM}}" }// Read an input's value
{ "type": "read", "selector": "#otp-input", "as": "OTP", "what": "value" }
101
{ "type": "read", "selector": "a.download-link", "as": "LINK", "what": "attribute", "attribute": "href" }// Read then use in a condition
{ "type": "read", "selector": "#quote-price", "as": "PRICE" }
{
"type": "if",
"var": "PRICE",
"contains": "$0",
"then": [
{ "type": "sheet_status", "value": "zero_price" },
{ "type": "exit_script" }
]
}Nesting
Branches can be nested — an if inside a one_of branch, or a one_of inside an if then block. The engine resolves them recursively and each nested random action pins independently.
{
"type": "if",
"detect": { "selector": ".options-page" },
"then": [
{
"type": "one_of",
"choices": [
[{ "type": "click", "selector": "#option-a" }],
[{ "type": "click", "selector": "#option-b" }]
]
}
],
"else": [
{ "type": "click", "selector": "#continue" }
]
}