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 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: 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. 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. XCUITest Locator Strategies: There are different agency to inspect & amp; use locators in XCUITest: 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: 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: 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. 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: TEST SCRIPT: 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. 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). Get the descendent DOM elements of a specific picker using the commands below. 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: Alternatively, early fashion to scrutinize on Non-XCode environments are: 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. Can be printed in Console section of Debug Area, using the below bidding Can be printed if used in test, by entering the bidding You can get discussing with our strife community Prints the required constituent inside test functions. Helpful for beginners and learners on initial point 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 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. 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. Most coating utilise XCUITest use the below require to happen elements in the app. 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… .. allows you to approach mobile apps on real iOS devices. You can scrutinize component for real time debugging. 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: Bear in mind that must be executed on real browsers for exact results. Detect bugs before users do by testing software in with BrowserStack. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.XCUITest Locators and How to find XCUIElement
What are XCUITest Locators?
What is an XCUIElement?
What are the different XCUITest Locator Strategies?
1. Get XCUIElement by Accessibility Identifier
homeImageView3.accessibilityIdentifier = `` homeImage3ForHomeScreen ''
2. Get XCUIElement by XPath
3. Get XCUIElement by Class name
4. Get XCUIElement by Label
Button, 0x283f81f80, {{20.0, 635.5}, {374.0, 62.0}}, label: 'WWE Mayhem, No1. WWE Arcade Action Game 'let gameRequired = `` WWE Mayhem, No1. WWE Arcade Action Game '' let buttonLabel = appStore .buttons [gameRequired] .firstMatch .label
5. Get XCUIElement by First Match
app.buttons.firstMatch
6. Get XCUIElement by Index
app.buttons.element (boundBy: 2)
7. Locate Elements by Subviews
app.scrollViews [`` Main ''] .descendants (matching: .button)
app.scrollViews [`` Main ''] .children (tally: .button)
How to find elements in XCUITest?
1. Debug View Hierarchy
2. Print accessibility hierarchy
po print (app.debugDescription)
mark (app.debugDescription)
Like what you are read?
3. UI Test Recorder
4. Accessibility Inspector
5. Inspect Element employ BrowserStack App Live
6. Appium Inspector
Which elements to find utilise XCUITest?
app.buttons.element How to find XCUITest Locators using BrowserStack App Live
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously