Skip to main content
Use for_loop_node to repeat actions for each value in a list—processing search results, downloading multiple files, or clicking through items.

Structure

{
  "type": "for_loop_node",
  "variable_name": "order_ids",
  "nodes": [
    {
      "type": "action_node",
      "interaction_action": {
        "click_element": {
          "command": "get_by_text(\"{order_ids[index]}\")",
          "prompt_instructions": "Click order {order_ids[index]}"
        }
      }
    }
  ],
  "reset_nodes": [],
  "on_error_in_loop": "raise"
}

Properties

PropertyTypeDescription
variable_namestrParameter to iterate over
nodeslist[action_node | if_else_node]Actions for each iteration
reset_nodeslist[action_node | if_else_node]Actions to run after each iteration
on_error_in_loop"continue" | "break" | "raise"Error handling behavior

The index Variable

Inside a loop, {variable[index]} references the current iteration’s value:
order_ids = ["ORD-001", "ORD-002", "ORD-003"]

Iteration 1: {order_ids[index]} → "ORD-001"
Iteration 2: {order_ids[index]} → "ORD-002"
Iteration 3: {order_ids[index]} → "ORD-003"

Data Sources

Loop variables can come from:
SourceWhen to Use
input_parametersKnown values before execution
generated_parametersValues extracted during automation
secure_parametersSensitive values from secure storage
For dynamic iteration, extract values first:
[
  {
    "type": "action_node",
    "extraction_action": {
      "llm": {
        "extraction_format": { "item_ids": "List[str]" },
        "output_variable_names": ["item_ids"],
        "extraction_instructions": "Extract all item IDs"
      }
    }
  },
  {
    "type": "for_loop_node",
    "variable_name": "item_ids",
    "nodes": [ ... ]
  }
]

Reset Nodes

Actions that run after each iteration to return the browser to a known state. Essential for loops that navigate away from the starting page.
{
  "type": "for_loop_node",
  "variable_name": "documents",
  "nodes": [
    {
      "type": "action_node",
      "interaction_action": {
        "click_element": {
          "command": "get_by_text(\"{documents[index]}\")"
        }
      }
    }
  ],
  "reset_nodes": [
    {
      "type": "action_node",
      "interaction_action": {
        "close_tabs_until": {
          "matching_url": "https://example.com/documents"
        }
      }
    }
  ]
}

Reset Strategy Recommendations

ActionReliabilityUse When
close_tabs_untilHighActions open new tabs
go_to_urlHighNavigate to known URL
click_element (navbar)MediumPersistent navigation exists
go_backLowAvoid—fails on errors
Avoid go_back for reset nodes. If an error occurs mid-loop, the browser may be on an unexpected page.

Error Handling

BehaviorDescription
"raise"Stop automation on error (default)
"continue"Skip failed iteration, continue to next
"break"Stop loop, continue with next node outside loop
{
  "type": "for_loop_node",
  "variable_name": "files",
  "on_error_in_loop": "continue",
  "nodes": [ ... ]
}
Use "continue" when some items may fail but you want to process as many as possible (e.g., downloading files where some may be missing).

Common Patterns

Download Multiple Files

{
  "type": "for_loop_node",
  "variable_name": "doc_links",
  "nodes": [{
    "type": "action_node",
    "interaction_action": {
      "click_element": {
        "command": "get_by_role(\"link\", name=\"{doc_links[index]}\")",
        "expect_download": true,
        "download_filename": "{doc_links[index]}.pdf"
      }
    }
  }]
}

Process Items and Return

{
  "type": "for_loop_node",
  "variable_name": "item_ids",
  "nodes": [
    {
      "type": "action_node",
      "interaction_action": {
        "click_element": {
          "command": "get_by_text(\"{item_ids[index]}\")"
        }
      }
    },
    {
      "type": "action_node",
      "extraction_action": {
        "llm": {
          "extraction_format": { "details": "str" },
          "extraction_instructions": "Extract item details"
        }
      }
    }
  ],
  "reset_nodes": [{
    "type": "action_node",
    "interaction_action": {
      "go_to_url": { "url": "https://example.com/items" }
    }
  }]
}

Limitations

  • Nested loops are not supported
  • Variable must be populated before loop execution
  • Only action_node and if_else_node allowed inside loops