Control Flow
figranium provides robust control flow mechanisms to handle dynamic web pages, pagination, and multi-step processes.
Conditional Execution (If)#
The If block executes a sequence of actions only when a condition is met.
Syntax#
- Type:
if - Condition:
- Expression: A JavaScript expression that evaluates to true/false.
exists('.error-message')text('.status') === 'Success'{$count} > 5
- Structured: Define
selector,operator(e.g.,equals,contains), andvalue.
- Expression: A JavaScript expression that evaluates to true/false.
- Else: Optional
elseblock to execute if the condition is false. - End: Required
endblock to close the conditional scope.
Example: Login Check#
{
"type": "if",
"value": "exists('.dashboard')"
},
{
"type": "stop",
"value": "success"
},
{
"type": "else"
},
{
"type": "type",
"selector": "#username",
"value": "{$user}"
},
{
"type": "end"
}
Loops (While Loop, Repeat, Loop Elements)#
While#
Executes a block of actions repeatedly as long as the condition remains true.
- Type:
while - Condition: Same as
if. - Usage: Pagination, waiting for a specific state.
For Each (foreach)#
Iterates over a list of elements matching a selector.
- Type:
foreach - Selector: The CSS selector matching multiple elements (e.g.,
.product-card). - Inside Loop: Use
loop.itemto interact with the current element.- Scope: Actions inside the loop are scoped to the current element.
clickwithout a selector clicks the current item.
- Scope: Actions inside the loop are scoped to the current element.
- Usage: Scraping lists of products, processing table rows.
Repeat N#
Executes a block a fixed number of times.
- Type:
repeat - Value: Number of iterations.
Error Handling (On Error)#
The On Error block (internally on_error) acts like a try/catch. If any action within the main flow fails (e.g., timeout, element not found), execution jumps to the Error Handler block.
- Usage: Handling CAPTCHAs, closing popups, retry logic.
- Resume: After the error block, execution can stop or continue (advanced).