> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-mobile/troubleshooting/tips/tips-to-stabilize-element-selection-image-recognition.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# 要素選択を安定させるTips (画像認識)

画像認識による要素探索は、レコーディング時に選択された位置周辺の見た目を元に要素を探します。 そのため、以下の点に気を付けると、要素を安定して選択できるようになります。

## 要素に特徴的な領域を選択する

選択した位置の周辺に何も表示されていなかったり、同じ見た目の領域が複数存在したりすると、安定性に影響する場合があります。 操作したい要素の特徴的な見た目の部分を選択することで、テストを安定化させることができます。 例として、以下の画像のように、白いエリアの選択を避け、特徴のある箇所を選択しましょう。

![](https://1076629499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fngfbmyfc37v4emfzEMM7%2Fuploads%2Fgit-blob-547401078674ee078cb816e10f2aa170d17193ba%2Fgood%20bad%20selection%201.png?alt=media)

## 頻繁に見た目が変わる部分を避ける

時刻や日付、または動的なコンテンツなど、テストを実行するたびに見た目が変わる要素が近くにあると安定性に影響する場合があります。 対象要素の中で、できるだけ見た目が安定している領域を選択してください。

## (応用)「検出パターン」を利用した要素探索

画像認識による要素探索についてより詳しく知ることで、テストを安定させるためのコツを掴みやすくなります。ここでは、画像認識ロケータが使用している「検出パターン」について解説します。

「検出パターン」とは画像認識ロケータが要素探索に使用する、スクリーンショットの一部を切り出したものです。要素探索プロセスは次のように進行します。

### タップ

1. レコーディング中に撮影されたスクリーンショットから、タップされた位置の周辺を切り出して検出パターンを作成する
2. テスト実行中の画面から、検出パターンに一致する位置を探す

検出パターンはテスト実行時に動的に作成されます。テスト中で使用された検出パターンはテスト結果画面で確認することができます。

操作したい要素の特徴的な見た目の部分をタップすることでテストを安定化させることができるのは、検出パターンに特徴的な部分が含まれるためです。

![](https://1076629499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fngfbmyfc37v4emfzEMM7%2Fuploads%2Fgit-blob-561666c49a050857e8521b46b93433dd8876e369%2FUntitled%20\(4\)\(2\).png?alt=media)

なお、操作したい位置が特徴的な見た目をしていなかったり、見た目が頻繁に変わってしまうなどにより要素探索が安定しない場合は、手動で検出パターンを定義することで問題を回避できる可能性があります。

検出パターンを手動で定義するにはクイック要素更新画面の **検出パターンの調整** で **手動** を選択します。

![](https://1076629499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fngfbmyfc37v4emfzEMM7%2Fuploads%2Fgit-blob-345010ad3e47cfd39a4d98784690a1ccb4f11871%2Fdetection_pattern_ja\(1\).png?alt=media)

このとき、**タップする場所は検出パターンの外側にあっても構いません**。タップしたい場所の見た目が頻繁に変わる場合でも、その近くに安定した要素がある場合には、検出パターンの外側をタップすることが有効です。

#### 💡Tips

例えば、以下の画像の場合では「Check Availability・Reserve」ボタン要素をタップしたいと仮定します。この時、対象要素上側の要素が変わる場合があるため、例えば、検出パターンをピンク色の枠 (下図例) で囲ってしまうと、失敗する可能性が考えられます。そのため、見た目が変わらないボタン要素の部分のみを含む範囲として指定 (下図例：青色枠) すると安定しやすいです。

![](https://1076629499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fngfbmyfc37v4emfzEMM7%2Fuploads%2Fgit-blob-c6349959b0c80735249e3ee32bd80ed2f5a2f9b1%2FScreenshot%202026-04-21%20at%2015.19.31.png?alt=media)

### 要素までスワイプ

要素までスワイプは、レコーディング時に対象要素までスワイプし、対象要素を選択すると検出パターンが表示されるため、対象要素の特徴を全て網羅するように検出パターンの範囲を調整します。 テスト実行時、画面から検出パターンに一致する位置を探し、その位置までスワイプします。

要素までスワイプの「検出パターンの調整」は「手動」で行う必要があります。

要素までスワイプについて、詳しくは[こちら](https://help.autify.com/nocode-mobile/using-autify-nocode-mobile/scenario-creation-and-maintenance/swipe-to-element.md)をご覧ください。

### 検出パターンの調整を利用しても要素選択が安定しない場合

もし選択したい要素の見た目が頻繁に変わる場合や、検出パターンの調整を利用しても要素選択が安定しない場合は、XPathやAccessibility IDロケータの使用をおすすめします。

#### 💡Tips

例えば、対象要素を以下の「EAST NIHONBASHI：SANDWICH」と仮定した時、「EAST NIHONBASHI：SANDWICH」というテキスト自体は同じですが、実行端末の横幅サイズなどに影響され、テキストが折り返してしまう仕組みが適用されるアプリケーションの場合、見た目が変わってしまうため、画像認識ロケータを利用していた場合、失敗する可能性があります。このようなケースの場合、XPathロケータをご利用いただくことをおすすめします。

![](https://1076629499-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fngfbmyfc37v4emfzEMM7%2Fuploads%2Fgit-blob-4f999ef383c4c27b1623d9827681a3bd8333dbbb%2FScreenshot%202026-04-21%20at%2015.22.12.png?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-mobile/troubleshooting/tips/tips-to-stabilize-element-selection-image-recognition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
