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

type: if
type: branch
type: 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.

ParamTypeDescription
detectoptionalobjectDetection block: selector, text, url_contains, frame_url_contains. Same format as page detect.
detect.modeoptionalstring"any" (default for if) or "all". How multiple signals combine.
timeoutoptionalnumberMs to wait for detect to become true. Default: 0 (check once, no waiting).
poll_msoptionalnumberPolling 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.

ParamTypeDescription
varoptionalstringVariable name (from read) or {{TEMPLATE}} to compare.
equalsoptionalstringTrue if var equals this value.
not_equalsoptionalstringTrue if var does not equal this value.
containsoptionalstringTrue if var contains this substring.
not_containsoptionalstringTrue if var does not contain this substring.
matchesoptionalstringTrue if var matches this regex pattern.
not_emptyoptionalbooleanTrue if var is not empty (has non-whitespace content).
emptyoptionalbooleanTrue if var is empty or whitespace-only.
ignore_caseoptionalbooleanCase-insensitive comparison. Default: false.

Combining & Branching

ParamTypeDescription
matchoptionalstring"all" (AND, default) or "any" (OR) — how detect + var results combine.
negateoptionalbooleanInvert the final result. Default: false.
thenrequiredarrayActions to run if the condition is true.
elseoptionalarrayActions to run if the condition is false. Alias: otherwise.
JSON
// Selector-based condition
{
  "type": "if",
  "detect": { "selector": "#error-message" },
  "then": [
    { "type": "click", "selector": "#retry-btn" }
  ],
  "else": [
    { "type": "click", "selector": "#continue" }
  ]
}
JSON
// Text-based condition
{
  "type": "branch",
  "detect": { "text": "Already registered" },
  "then": [
    { "type": "sheet_status", "value": "duplicate" },
    { "type": "exit_script" }
  ]
}
JSON
// 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" }
  ]
}
JSON
// 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" }
  ]
}
JSON
// 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

type: 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).

ParamTypeDescription
choicesrequiredarrayArray of action arrays. Each inner array is one possible branch. Single actions are auto-wrapped.
pickoptionalstringSelection strategy. Default: "random".
repick_on_retryoptionalbooleanIf true, re-randomize on step retry instead of reusing the pinned branch. Default: false.
JSON
{
  "type": "one_of",
  "choices": [
    [{ "type": "click", "selector": "#plan-basic" }],
    [{ "type": "click", "selector": "#plan-premium" }],
    [{ "type": "click", "selector": "#plan-family" }]
  ]
}
JSON
// 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

type: 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.

ParamTypeDescription
selectorrequiredstring | arrayCSS selector or array of selectors for the element to read from.
asrequiredstringVariable name to store the result. Must start with a letter or underscore. Use as {{VAR_NAME}} in later actions. Alias: var.
whatoptionalstring"text" (default) — visible text; "value" — input value or checkbox state; "attribute" — a specific HTML attribute.
attributeoptionalstringRequired when what is "attribute". The HTML attribute name to read (e.g. "href", "data-id"). Alias: attr.
indexoptionalnumberWhich visible match to read from (0 = first). Default: 0.
JSON
// Read visible text
{ "type": "read", "selector": "#confirmation-number", "as": "CONF_NUM", "what": "text" }

111
{ "type": "sheet_comment", "value": "Confirmation: {{CONF_NUM}}" }
JSON
// 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" }
JSON
// 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.

JSON
{
  "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" }
  ]
}