Real-world automation rarely moves in a straight line. Pages branch based on cookies, user state, and available inventory. RTILA X provides flow-control commands that let the engine make decisions at runtime.
Conditional Branches
The if command accepts a condition object rather than a top-level expression. The conditionβs type can be "element_visible", "script", or "variable_contains". Depending on the type, include selector, expression, or variable and value. Commands to run when the condition is true belong in the then array; the optional else array supplies an alternate path.
{
"command": "if",
"params": {
"condition": {
"type": "element_visible",
"selector": "css=.cart-empty"
},
"then": [
{
"command": "goto",
"params": {
"url": "https://learn.rtila.com/scenarios/conditional-logic/1"
}
}
],
"else": []
}
}
Use ${variable} syntax inside command expressions. Triggers use single-brace {variable} syntax, while commands use dollar-brace syntax. Keep this distinction consistent.
While Loops
A while loop repeats a command block while its condition object remains true. The commands that run inside the loop are placed in the do array. This pattern is commonly used for pagination until a βNextβ button disappears.
{
"command": "while",
"params": {
"condition": {
"type": "script",
"expression": "document.querySelector('.next-page') !== null"
},
"do": []
}
}
Be careful to include a progression step inside the loop body. Without one, the loop can run indefinitely or until the engine times out.
For Each
for_each iterates over a dataset or variable and runs a command block for each item. Set source_type to "dataset" or "variable", provide the matching dataset or variable name, and specify the iterator name with as. Commands for each iteration live in the do array.
{
"command": "for_each",
"params": {
"source_type": "dataset",
"dataset": "products",
"as": "item",
"do": []
}
}
Repeat
repeat runs a command block a fixed number of times. Supply the iteration count as times and put the repeated commands in the do array. Use it for polling a status page, retrying an action, or waiting for queued data.
{
"command": "repeat",
"params": {
"times": 3,
"do": []
}
}
Try / Catch
Complex workflows should wrap risky steps in try_catch so one failing selector does not abort the entire run. The try array runs first; if any command in it fails, execution moves to the catch array. RTILA X does not have a finally block.
{
"command": "try_catch",
"params": {
"try": [],
"catch": []
}
}
This pattern is especially important on flaky pages, rate-limited APIs, and dynamically rendered single-page applications.
Break and Continue
Inside loops, break stops the current loop, while continue skips to the next iteration. Both commands take an empty params object.
{
"command": "break",
"params": {}
}
{
"command": "continue",
"params": {}
}
These commands keep loops responsive and allow you to exit early when a sentinel value appears.
Infinite Scrolling
Infinite scroll pages do not load all content at once. The infinite_scroll command scrolls until a condition is met or until no new content appears. Use selector to target a container (empty for window scrolling), max_scrolls to cap iterations (0 means unlimited until no new content appears), scroll_delay to pause between scrolls, and do for commands executed before each scroll.
{
"command": "infinite_scroll",
"params": {
"selector": "css=.product-list",
"max_scrolls": 25,
"scroll_delay": 1500,
"do": []
}
}
Try It Yourself
Run Conditional Logic scenario 1 to see branch behavior. Then start Loops scenario 1 and Error Handling scenario 4. These three pages give immediate visual feedback about the execution path.
Was this helpful?
Thank you for your feedback!