# 循环

节点类型 `browser_loop`

## 功能说明

按次数、集合、元素列表或条件重复执行一组步骤。

## 客户端配置界面

![循环节点的客户端配置界面](/assets/loop.05af990d8a1370b3ba27df4f2866f602b0bf111eae56e77efd72402fe3cdc089.0538f3a9.webp)

截图来自 MoreLogin 桌面客户端 V2.73.101 的英文界面。

## 输入字段

以下字段位于 `data.browserUi.inputs`。

| 字段 | 类型或取值 | Schema 必填 | 执行默认值 | 说明与边界 |
|  --- | --- | --- | --- | --- |
| `loopMode` | `"times"` / `"elements"` / `"list"` / `"while"`（支持变量引用） | 否 | `"times"` | 循环方式 编辑器初值 `"times"` |
| `times` | `WorkflowNumber` | 否 | `3` | 循环次数; integer; minimum after resolution: 1; maximum after resolution: 10000 编辑器初值 `3` |
| `selectorRadio` | `"CSS"` / `"XPath"`（支持变量引用） | 否 | `"CSS"` | 定位方式 编辑器初值 `"CSS"` |
| `selector` | `string` | 否 | — | 选择器 |
| `serial` | `WorkflowNumber` | 否 | `1` | 元素序号; integer; minimum after resolution: 1 编辑器初值 `1` |
| `type` | `"object"` / `"innerText"` / `"innerHTML"` / `"attribute"` / `"contentFrame"`（支持变量引用） | 否 | `"innerText"` | 输出类型 编辑器初值 `"innerText"` |
| `key` | `string` | 否 | — | 属性名 / 子元素选择器 |
| `content` | `["null","boolean","number","string"]` / array<`JSON`> / `object`（支持变量引用） | 否 | — | 列表数据 |
| `loopConditions` | array<`object`> | 否 | — | 当满足条件时 |
| `maxIterations` | `WorkflowNumber` | 否 | `10000` | 最大循环次数; integer; minimum after resolution: 1; maximum after resolution: 10000 编辑器初值 `10000` |
| `accumulatorMode` | `"none"` / `"collect"` / `"count"` / `"sum"`（支持变量引用） | 否 | `"none"` | 累计方式 编辑器初值 `"none"` |
| `initialState` | `["null","boolean","number","string"]` / array<`JSON`> / `object`（支持变量引用） | 否 | — | 累计初始值 |
| `accumulatorPath` | `string` | 否 | — | 累计字段路径（留空使用本轮结果） |
| `breakEnabled` | `boolean`（支持变量引用） | 否 | `false` | 提前退出条件 编辑器初值 `false` |
| `breakCondition` | `object` | 否 | — | 满足时退出 |


## 条件与边界

- 四类循环均执行 maxIterations 上限（while 达到上限时正常结束，exitReason=max_iterations）；accumulatorMode 指定 none/collect/count/sum（省略按 none），initialState 指定初始值，accumulatorPath 取最后节点 data 内的值，breakEnabled/breakCondition 控制提前退出。while 的 loopConditions 只接受规则数组 [{field,operator,value}]。index 从 1 开始；对象列表 item={key,value}。type 只有 object/innerText/innerHTML/attribute/contentFrame，type=attribute 要求 key。跳过分支不复用上一轮输出。
- 校验错误码 `RPA_NODE_INPUT_INVALID`


## 输入引用

| 字段 | 允许的形式 |
|  --- | --- |
| `loopMode` | `literal`, `template` |
| `times` | `literal`, `numericExpression` |
| `selectorRadio` | `literal`, `template` |
| `selector` | `literal`, `template` |
| `serial` | `literal`, `numericExpression` |
| `type` | `literal`, `template` |
| `key` | `literal`, `template` |
| `content` | `literal`, `template` |
| `loopConditions` | `literal` |
| `maxIterations` | `literal`, `numericExpression` |
| `accumulatorMode` | `literal`, `template` |
| `initialState` | `literal`, `template` |
| `accumulatorPath` | `literal`, `template` |
| `breakEnabled` | `literal`, `template` |
| `breakCondition` | `literal` |


## 输出字段

| 输出字段 | 类型或取值 |
|  --- | --- |
| `index` | `number` / `null` |
| `item` | `["null","boolean","number","string"]` / array<`JSON`> / `object` |
| `total` | `number` |
| `iterationCount` | `number` |
| `completedCount` | `number` |
| `exited` | `boolean` |
| `state` | `["null","boolean","number","string"]` / array<`JSON`> / `object` |
| `results` | array<`["null","boolean","number","string"]` / array<`JSON`> / `object`> |
| `exitReason` | `"break"` / `"condition_false"` / `"max_iterations"` / `"completed"` |


按契约用 `${nodeId.data.field}` 引用公开字段。

## JSON 示例

可放入流程 `nodes` 数组或其他节点 `blocks` 中的完整节点对象。

```json
{
  "id": "repeat_three_times",
  "type": "browser_loop",
  "data": {
    "title": "重复检查三次",
    "browserAction": "loop",
    "browserUi": {
      "inputs": {
        "loopMode": "times",
        "times": 3,
        "accumulatorMode": "none"
      }
    }
  },
  "blocks": [
    {
      "id": "reload_each_time",
      "type": "browser_refreshPage",
      "data": {
        "title": "刷新页面",
        "browserAction": "refreshPage",
        "browserUi": {
          "inputs": {
            "postWaitMs": 1000
          },
          "exception": {
            "timeout": 30000,
            "policy": "interrupt"
          }
        }
      }
    }
  ]
}
```

[返回节点目录](/zh/browser-rpa/nodes)