# simulator_find

> 這個 MCP 工具會列出團隊模擬器螢幕上符合選擇器的每個元素，最相符的在前，不碰觸任何內容。

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

`simulator_find` 會傳回團隊正在執行的模擬器螢幕上符合選擇器的每個可用元素，最相符的在前，還會傳回符合但被排除的元素及原因（隱藏、在螢幕外）。它不碰觸任何內容，也不等待：還沒出現的元素會得到空清單。它是唯讀的。在 [simulator_tap](https://air.build/tw/docs/mcp-tools/simulator_tap/) 操作之前，用它檢查選擇器會命中什麼。

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

## 選擇器

元素工具（[simulator_tap](https://air.build/tw/docs/mcp-tools/simulator_tap/)、[simulator_find](https://air.build/tw/docs/mcp-tools/simulator_find/)、[simulator_wait](https://air.build/tw/docs/mcp-tools/simulator_wait/)、[simulator_slider](https://air.build/tw/docs/mcp-tools/simulator_slider/)、[simulator_adjust](https://air.build/tw/docs/mcp-tools/simulator_adjust/)，以及 [simulator_batch](https://air.build/tw/docs/mcp-tools/simulator_batch/) 的步驟）以選擇器而不是座標指定元素。元素會在 [simulator_describe_ui](https://air.build/tw/docs/mcp-tools/simulator_describe_ui/) 顯示的輔助使用樹中查找，每次都重新讀取，所以無論版面把它放在哪裡都能找到。不在輔助使用樹中的內容無法被選取；請對它使用座標。

| 欄位 | 類型 | 比對什麼 |
| --- | --- | --- |
| `text` | string | 元素的可見文字：它的標籤（或標題）或它的值。不區分大小寫，忽略兩端的空格，除非設定了 `exact`，否則只需符合文字的一部分 |
| `id` | string | 元素的 `accessibilityIdentifier`，完全相符 |
| `value` | string | 只比對元素的值，例如輸入欄位的文字。不區分大小寫；除非設定了 `exact`，否則只需符合一部分 |
| `role` | string | 輔助使用角色，完全相符，例如 `AXButton`、`AXSlider`、`AXSwitch` |
| `nodeId` | string | 來自 [simulator_describe_ui](https://air.build/tw/docs/mcp-tools/simulator_describe_ui/) 或本工具的 `nodeId`：剛好是那個元素，不會是其他元素 |
| `exact` | boolean | `text` 和 `value` 必須與元素的文字完全相同，而不只是出現在其中 |
| `strict` | boolean | 有多個可用元素符合時失敗，而不是取最相符的那一個 |

`text`、`id`、`value`、`role` 和 `nodeId` 至少提供一個；空字串視為未提供。提供的每個欄位都必須相符。

**排序。** 有多個元素符合時，最相符的排在最前：文字與查詢相同優先於文字包含查詢；符合標籤優先於符合值；按鈕、連結、輸入欄位、開關或儲存格優先於文字相同的靜態文字；然後是較小的元素；然後由上到下、由左到右。對單一元素操作的工具會取第一個，並回報 `matchCount`：大於 1 表示由排序決定。加入 `id`、`role`、`exact` 或 `strict` 可以確保選中目標。

**排除。** 符合但無法使用的元素會列在 `excluded` 下，並帶有 `reason`：`hidden`、`empty-frame`（沒有尺寸）、`off-screen`（中心在螢幕外），對於點一下還有 `disabled`。

**nodeId。** `nodeId` 指稱 App 目前執行狀態下的一個元素。元素消失、被隱藏、移出螢幕或 App 重新啟動後，它就會失效：這時請重新讀取樹。請把它視為不透明的值，不要保存以供日後使用。

**選擇器錯誤**（任何元素工具）：

| 訊息 | 何時出現 | 處理方式 |
| --- | --- | --- |
| Name the element: text, id, value, role or nodeId. | 沒有提供任何選擇器欄位 | 加入一個 |
| invalid nodeId; use the opaque string returned by describe-ui | `nodeId` 不是工具提供的值 | 從 [simulator_describe_ui](https://air.build/tw/docs/mcp-tools/simulator_describe_ui/) 原樣複製 |
| node_id_device_mismatch: nodeId belongs to a different device | 該 `nodeId` 來自另一個模擬器 | 讀取這台裝置的樹 |
| stale_node: _nodeId_ is absent, hidden, disabled, off-screen, or no longer matches; describe UI again | 元素已消失或已變更 | 再次呼叫 [simulator_describe_ui](https://air.build/tw/docs/mcp-tools/simulator_describe_ui/) |
| ambiguous selector _selector_: _n_ usable matches; add an id, role, or value filter | 使用了 `strict`（或 `nodeId`），但有多個元素符合 | 縮小選擇器的範圍 |
| no usable element matching _selector_ within _n_s | 會等待的工具在時限內沒有找到可用的元素；如果有元素符合但無法使用，後面會附上 `(matched but skipped: 1 hidden, …)` | 用 `simulator_find` 檢查，用 [simulator_scroll_to](https://air.build/tw/docs/mcp-tools/simulator_scroll_to/) 捲動，或等待更久 |

## 輸入

| 輸入 | 類型 | 必填 | 預設值 | 作用 |
| --- | --- | --- | --- | --- |
| `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` |
| `text`, `id`, `value`, `role`, `nodeId`, `exact`, `strict` | 請參閱 [選擇器](https://air.build/tw/docs/mcp-tools/simulator_find/#selector) | 前五個中至少一個 | — | 選擇器 |

## 結果

| 欄位 | 說明 |
| --- | --- |
| `ok` | `true` |
| `matches` | 可用的元素，最相符的在前；沒有時為空 |
| `matches[].element` | 元素：`label`、`value`、`identifier`、`nodeId`、`role`、`frame`（`x`、`y`、`width`、`height`）、`enabled`、`interactive`（接受輸入）、`hidden`，某些控制項還有 `activationPoint`、`sliderTrack`、`adjustable`、`adjustmentActions` |
| `matches[].point` | `x`、`y`：點一下它時落下的位置，使用 [螢幕座標](https://air.build/tw/docs/mcp-tools/simulator_screen/#coordinates) |
| `matches[].exact` | 它的文字是否與查詢相同（對於 `id` 一律為 `true`） |
| `excluded` | 符合但無法使用的元素 |
| `excluded[].element` | 元素，同上 |
| `excluded[].reason` | `hidden`、`empty-frame`、`off-screen` 或 `disabled` |

```json
{
  "ok": true,
  "matches": [
    { "element": { "label": "New note", "identifier": "new-note", "nodeId": "ax1:…", "role": "AXButton",
                   "frame": { "x": 16, "y": 120, "width": 370, "height": 52 }, "enabled": true, "interactive": true, "adjustable": false },
      "point": { "x": 201, "y": 146 }, "exact": true }
  ],
  "excluded": []
}
```

## 錯誤

上述的 [選擇器錯誤](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_find", "arguments": {"teamId": "00000000-0000-0000-0000-000000000000", "text": "New note"}}
```
