> 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/en/troubleshooting/tips/tips-to-stabilize-element-selection-xpath-and-accessibility-id.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# Tips for selecting elements reliably (XPath and Accessibility ID)

If Autify cannot reliably select the right element via image recognition, using XPath or Accessibility ID may help. In this section, we will show you how to select an element using XPath and Accessibility ID.

## XPath <a href="#xpath" id="xpath"></a>

If you chose XPath as the locator, Autify will automatically generate an XPath. The auto-generated XPath only includes the element type and its display order. You can improve reliability by supplying additional information or removing unnecessary information from the XPath.

Example:

| Type                    | Example of XPath                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Feature                                                                                                                                                                                                                                |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Auto-generated          | /XCUIElementTypeApplication/XCUIElementTypeWindow\[1]/XCUIElementTypeOther/XCUIElementTypeOther/<>XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell\[2]/XCUIElementTypeOther\[1]/XCUIElementTypeOther/XCUIElementTypeSecureTextField | It refers to the entire tree of the element, so changes that are not directly related to the element may have an effect. It only looks at the type and order of the element, so the wrong element is selected if the order is changed. |
| After manual adjustment | //XCUIElementTypeCell\[contains(@value, “Password”)]//XCUIElementTypeSecureTextField                                                                                                                                                                                                                                                                                                                                                                                                    | Only includes information that is important for locating the element, which improves stability. Learning requires some trial and error.                                                                                                |

Below are examples of commonly used XPaths:

### Using attributes

On the Quick Element Update page, if the target element or its parent-child elements have distinctive attributes, including them in the XPath can improve reliability. Here are examples that use the *value* attribute.

| XPath                                 | Element to be selected                |
| ------------------------------------- | ------------------------------------- |
| //XCUIElementTypeButton\[@value="OK"] | Button whose value is "OK"            |
| //\*\[contains(@name, ‘limited’)]     | Element whose name includes "limited" |
| //\*\[starts-with(@name, "2024")]     | Element whose name starts with "2024" |
| //\*\[ends-with(@name, "login")]      | Element whose name ends with "login"  |
| //\*\[@name="Return"]                 | Element whose name is "Return"        |
| (//\*\[@name="Done" or "完了"])         | Element whose name is "Done" or "完了"  |

### Specifying the order

When multiple elements match the XPath, you can select an element by its order.

| XPath                               | Element to be selected |
| ----------------------------------- | ---------------------- |
| //XCUIElementTypeButton\[3]         | The third button       |
| //XCUIElementTypeTextField\[last()] | The last text field    |

### Composite locator

If the element you want to select lacks distinctive characteristics, you can select it based on its relative relationship with other elements.

| XPath                                             | Element to be selected                                       |
| ------------------------------------------------- | ------------------------------------------------------------ |
| //\*\[@value=”register”]//XCUIElementTypeButton   | Button within an element whose value is "register"           |
| //\*\[value=”Check out”] \~ XCUIElementTypeButton | Button adjacent to an element whose value is "Check out"     |
| //\[@name=”List”]/\[5]                            | Fifth element directly under an element whose name is "List" |

## Accessibility ID

If Autify cannot select an element using other methods, we recommend setting up Accessibility ID.

If the target element has the "name" attribute for iOS or the "content-desc" attribute for Android, the target element can be selected by setting the attribute value as the Accessibility ID on the Quick Element Update page.

If the target element does not have an Accessibility ID, you need to modify the application code.

### Setting up Accessibility ID

### iOS Native

Add the [accessibilityIdentifier](https://developer.apple.com/documentation/uikit/uiaccessibilityidentification/1623132-accessibilityidentifier) property to the target element.

### Android Native

Add contentDescription to the target element.

### Flutter

(iOS) Set the [Semantics identifier property](https://api.flutter.dev/flutter/semantics/SemanticsData/identifier.html) for the target element.

(Android) Currently unavailable. If you set the Semantics identifier property for an element, it will appear as a property called “resource-id” in the page source, so you can use it in an XPath.

### ReactNative

(iOS) Set the [testID property](https://reactnative.dev/docs/next/view#testid) for the target element.

(Android) Currently unavailable. If you set the testID property for an element, it will appear as an attribute called “resource-id” in the page source, so you can use it in an XPath.


---

# 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/en/troubleshooting/tips/tips-to-stabilize-element-selection-xpath-and-accessibility-id.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.
