# simulator_wait

> 這個 MCP 工具會在團隊的模擬器上等待某個元素出現或消失，或等待螢幕不再變化。

Source: https://air.build/tw/docs/mcp-tools/simulator_wait/

`simulator_wait` 會在團隊正在執行的模擬器上等待螢幕上發生某件事，然後回答：

- `visible`：直到與選擇器相符的元素出現在螢幕上（已停用的元素也算可見）；
- `hidden`：直到不再有元素與它相符；
- `idle`：直到螢幕的輔助使用樹在 `stableSeconds` 內沒有變化。在會產生動畫或載入的操作之後使用它。單純的載入指示器不會改變樹，所以算作閒置。

它不會觸碰任何內容，是唯讀的。選擇器的說明請參閱 [選擇器](https://air.build/tw/docs/mcp-tools/simulator_find/#selector)；`idle` 不需要選擇器。

| 唯讀 | 破壞性 | 冪等 |
| --- | --- | --- |
| 是 | 否 | 是 |

## 輸入

| 輸入 | 類型 | 必填 | 預設值 | 作用 |
| --- | --- | --- | --- | --- |
| `teamId` | 字串（UUID） | 是 | — | 團隊，來自 [list_teams](https://air.build/tw/docs/mcp-tools/list_teams/) |
| `simulator` | string | 否 | 團隊的預設裝置 | 哪種裝置，使用 [list_simulators](https://air.build/tw/docs/mcp-tools/list_simulators/#result) 中的 `id` |
| `state` | 字串：`visible`、`hidden` 或 `idle` | 是 | — | 要等待什麼 |
| `text`, `id`, `value`, `role`, `nodeId`, `exact`, `strict` | 請參閱 [選擇器](https://air.build/tw/docs/mcp-tools/simulator_find/#selector) | 與 `visible` 和 `hidden` 一起使用 | — | 元素 |
| `timeoutSeconds` | 數字，0 到 600 | 否 | `10` | 等待多久 |
| `stableSeconds` | 數字，0 到 10 | 否 | `0.5` | `idle` 時：螢幕必須維持不變的時間 |

## 結果

| 欄位 | 說明 |
| --- | --- |
| `ok` | `true` |
| `state` | `visible`、`hidden` 或 `idle` |
| `elapsedMs` | 等待了多久，以毫秒計 |
| `element`, `point`, `exact`, `matchCount`, `excluded` | `visible` 時：找到的元素，與 [simulator_tap](https://air.build/tw/docs/mcp-tools/simulator_tap/#result) 中相同 |

```json
{ "ok": true, "state": "hidden", "elapsedMs": 1250 }
```

## 錯誤

| 訊息 | 何時出現 | 處理方式 |
| --- | --- | --- |
| state must be one of visible, hidden, idle. | 缺少 `state`，或它是其他值 | 傳送這三個值之一 |
| no usable element matching _selector_ within _n_s | `visible`：它沒有及時出現 | 等待更久，或用 [simulator_find](https://air.build/tw/docs/mcp-tools/simulator_find/) 檢查選擇器 |
| element _selector_ disappearing did not happen within _n_s | `hidden`：它仍然存在 | 等待更久 |
| UI settling for _s_s did not happen within _n_s | `idle`：螢幕一直在變化 | 等待更久，或改用選擇器 |

另外還有其他 [選擇器錯誤](https://air.build/tw/docs/mcp-tools/simulator_find/#selector)，以及每個模擬器工具都可能傳回的錯誤：請參閱 [start_simulator](https://air.build/tw/docs/mcp-tools/start_simulator/#device-errors)。

## 範例

```json
{"name": "simulator_wait", "arguments": {"teamId": "00000000-0000-0000-0000-000000000000", "state": "visible", "text": "Saved", "timeoutSeconds": 30}}
```
