# ループ

ノードタイプ `browser_loop`

## 機能

回数、コレクション、要素のリスト、または条件に基づいて、ブロックを繰り返します。

## デスクトップクライアントでの設定

![デスクトップクライアントでの「ループ」の設定](/assets/loop.05af990d8a1370b3ba27df4f2866f602b0bf111eae56e77efd72402fe3cdc089.0538f3a9.webp)

MoreLogin デスクトップクライアント V2.73.101 の英語インターフェースで撮影しました。

## 入力

これらのフィールドは `data.browserUi.inputs` に置きます。

| フィールド | 型または値 | スキーマで必須 | 実行時の既定値 | 説明と制約 |
|  --- | --- | --- | --- | --- |
| `loopMode` | `"times"` / `"elements"` / `"list"` / `"while"`（変数参照をサポート） | いいえ | `"times"` | ループモード。エディターの初期値：`"times"` |
| `times` | `WorkflowNumber` | いいえ | `3` | ループ回数。整数、解決後の最小値：1、解決後の最大値：10000。エディターの初期値：`3` |
| `selectorRadio` | `"CSS"` / `"XPath"`（変数参照をサポート） | いいえ | `"CSS"` | セレクターの種類。エディターの初期値：`"CSS"` |
| `selector` | `string` | いいえ | — | セレクター |
| `serial` | `WorkflowNumber` | いいえ | `1` | 要素のインデックス。整数、解決後の最小値：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` | 最大反復回数。整数、解決後の最小値：1、解決後の最大値：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` | いいえ | — | 条件を満たしたら終了 |


## モードごとの要件と制限

- 4 種類のループはいずれも 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": "Repeat the check three times",
    "browserAction": "loop",
    "browserUi": {
      "inputs": {
        "loopMode": "times",
        "times": 3,
        "accumulatorMode": "none"
      }
    }
  },
  "blocks": [
    {
      "id": "reload_each_time",
      "type": "browser_refreshPage",
      "data": {
        "title": "Reload the page",
        "browserAction": "refreshPage",
        "browserUi": {
          "inputs": {
            "postWaitMs": 1000
          },
          "exception": {
            "timeout": 30000,
            "policy": "interrupt"
          }
        }
      }
    }
  ]
}
```

[ノードカタログに戻る](/ja/browser-rpa/nodes)