Skip to content

Control Flow Commands

Execute commands conditionally.

Parameter Type Required Description
condition.type string Condition type: element_visible, script, variable_contains
condition.selector string If element_visible Element selector to check
condition.expression string If script JavaScript expression returning true/false
condition.variable string If variable_contains Variable name to check
condition.value string If variable_contains Value to search for
then array Commands to run if condition is true
else array Commands to run if condition is false

Example — Element Visible:

if:
condition:
type: element_visible
selector: css=.cookie-banner
then:
- click: css=.accept-cookies
else: []

Example — Script:

if:
condition:
type: script
expression: "variables.price > 100"
then:
- click: css=.buy-now

Example — Variable Contains:

if:
condition:
type: variable_contains
variable: page_title
value: "Error"
then:
- goto: https://example.com/fallback

Loop while a condition is true.

Parameter Type Required Description
condition object Same as if condition
do array Commands to repeat

Example:

while:
condition:
type: element_visible
selector: css=.next-page
do:
- click: css=.next-page
- wait_for_load_state
- extract_data: products

Iterate over a dataset or list variable.

Parameter Type Required Description
source_type string dataset or variable
dataset string If dataset Dataset name to iterate
variable string If variable List variable name
as string Variable name for current item (default: item)
do array Commands to run for each item

Example:

for_each:
source_type: dataset
dataset: products
as: product
do:
- goto: ${product.url}
- extract_data: product_details

Repeat commands a fixed number of times.

Parameter Type Required Description
times number Number of repetitions
do array Commands to repeat

Handle errors gracefully.

Parameter Type Required Description
try array Commands to attempt
catch array Commands to run if an error occurs

Example:

try_catch:
try:
- click: css=.submit-button
- wait_for_selector: css=.success-message
catch:
- comment: "Submit failed, trying alternative"
- click: css=.submit-button-alt

Exit the current for_each or while loop.

Skip to the next iteration of the current loop.