XCUITest Locators and How to find XCUIElement

On This Page What are XCUITest Locators?What is an XCUIElement?January 27, 2026 · 5 min read · Testing Guide

XCUITest Locators and How to find XCUIElement

What are XCUITest Locators?

XCUITest Locators aid in place and testing the UI elements in UI Layers of the application.

Ideally, It is a good practice to store all XCUI locators in a well segregated location in project, which can be either a:

  • Class,
  • Enum,
  • Struct or
  • Protocol.

These locators are so called in trial or page object classes for automation of test scenario.

In the XCUITest API, the UI Elements are likewise known as XCUIElement. Hence, let us deep dive a bit on XCUIElement as well in the XCode environment.

What is an XCUIElement?

XCUIElement is an important class of the XCUITest API. It is an UI Element in an application under test. It provides us a way to test the app like an end user uses the app, perform some actions on the UI constituent using gestures & amp; keypad interactions.

What are the different XCUITest Locator Strategies?

XCUITest Locator Strategies:

  1. Get XCUIElement by Accessibility Identifier
  2. Get XCUIElement by XPath
  3. Get XCUIElement by Class gens
  4. Get XCUIElement by Label
  5. Get XCUIElement by First Match
  6. Get XCUIElement by Index
  7. Locate Elements by Subviews

There are different agency to inspect & amp; use locators in XCUITest:

1. Get XCUIElement by Accessibility Identifier

The convenient and about efficient way to locate ingredient for XCUITest is using accessibility identifiers. Unique identifier for an UI element set by the developer/QA in application ’ s source code.

Accessibility Identifiers can be contribute to the development code through both:

  • Storyboardafter navigating to “ Identity Inspector ” view on the correct panel
  • Functional programmingby setting the identifier in dev source code itself by writing the below line:
homeImageView3.accessibilityIdentifier = `` homeImage3ForHomeScreen ''

2. Get XCUIElement by XPath

Find the app xml source using XPath. This is slower and has execution issues. Practically, not recommended to be used. Below is an Example of an element ’ s XPath extracted from BrowserStack Inspector:

3. Get XCUIElement by Class name

It is usually the class name of the XCUI Element which begins with XCUIElementType. This is usually to be combined with another locator & amp; is name by ‘ Type ’ keyword.

4. Get XCUIElement by Label

It can be use if the Accessibility Identifier is not present in the app. However, it is preferred to add accessibility identifiers to all elements in the app.

HIERARCHY:

Button, 0x283f81f80, {{20.0, 635.5}, {374.0, 62.0}}, label: 'WWE Mayhem, No1. WWE Arcade Action Game '

TEST SCRIPT:

let gameRequired = `` WWE Mayhem, No1. WWE Arcade Action Game '' let buttonLabel = appStore .buttons [gameRequired] .firstMatch .label

5. Get XCUIElement by First Match

Get the first Element. For an example, if there are 10 buttons in the app screen, the below command would retrovert the first push in the screen.

app.buttons.firstMatch

6. Get XCUIElement by Index

Get any specific Element by Index. For an example, if there are 10 buttons in the app screen, the below command would render the 3rd button in the blind (considering, indicant start from 0).

app.buttons.element (boundBy: 2)

7. Locate Elements by Subviews

Get the descendent DOM elements of a specific picker using the commands below.

app.scrollViews [`` Main ''] .descendants (matching: .button)
app.scrollViews [`` Main ''] .children (tally: .button)

How to find elements in XCUITest?

There are different ways to find elements in XCUITest on XCode IDE, which are listed below:

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

Methods to find elements in XCUITest:

  1. Debug View Hierarchy
  2. Print Hierarchy
  3. UI Test Recorder
  4. Accessibility Inspector

Alternatively, early fashion to scrutinize on Non-XCode environments are:

  • – Inspect

1. Debug View Hierarchy

Activated on Debug Mode only. It intermit the app in its current state, permit the programmer to visit and understand the UI hierarchy of any app.

2. Print accessibility hierarchy

Can be printed in Console section of Debug Area, using the below bidding

po print (app.debugDescription)

Can be printed if used in test, by entering the bidding

mark (app.debugDescription)

Like what you are read?

You can get discussing with our strife community

3. UI Test Recorder

Prints the required constituent inside test functions. Helpful for beginners and learners on initial point

4. Accessibility Inspector

This is too helpful when user is accessing the app in blackbox way. Select XCode & gt; Open Developer Tool & gt; Accessibility Inspector & gt; Select Simulator & gt; Inspect factor

5. Inspect Element employ BrowserStack App Live

Locally building & amp; specify up can be time consume. Hence, this is a very handy usance which is both easy and tight to use. We will deep honkytonk on this towards the end of this article.

6. Appium Inspector

Inspecting locator components via Appium Inspector is another way to find and place elements in XCUITest. Although, this is not mostly employ, when we are already in an XCode environs where we have total control of the dev and test environment.

Which elements to find utilise XCUITest?

Most coating utilise XCUITest use the below require to happen elements in the app.

app.buttons.element

app.alerts.element

app.browsers.element

app.checkboxes.element

app.datePickers.element

app.comboBoxes.element

app.dialogs.element

app.icons.element

app.images.element

app.label.element

app.maps.element

app.popovers.element

app.pageIndicators.element

app.progressIndicators.element

app.placeholderValue.element

app.radioButtons.element

app.staticTexts.element

app.toggles.element

app.windows.element

.. and many more… ..

How to find XCUITest Locators using BrowserStack App Live

allows you to approach mobile apps on real iOS devices. You can scrutinize component for real time debugging.

Talk to an Expert

Steps to Locate app elements in BrowserStack are as postdate:

Step 1 Upload .ipaof app in portal (or use the sample app).

Step 2Choose an iOS Device from the list of devices for try and locating.

Step 3Post device selection and app launching, go to ‘ Inspect ’ subdivision, to locate the elements of the app utilise BrowserStack.

Step 4Click on the above distinguish play icon on the inspect view to start locating factor.

Step 5Perform the below actions by enlarging the accordions or by tapping on the app elements and research the locater identifiable on the app on UI level.

Step 6Locate all XCUI Elements by:

  1. Type – Class Name
  2. Value
  3. Name – ID
  4. Label
  5. Index

Conclusion

Bear in mind that must be executed on real browsers for exact results. Detect bugs before users do by testing software in with BrowserStack.

Tags
79,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free