How to Find Elements in iOS (Not) By XPath

January 13, 2026 · 9 min read · Mobile Testing

HeadSpin Platform
Automated & amp; manual testing made easy through data skill insights.
Differentiating capability:
  • Extended end-to-end automation of QA process
  • Comparative analysis of app performance against peers
  • Uninterrupted monitoring of app execution expend synthetic data for higher accessibility of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Affordable Existent Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based examination

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Finding Elements in iOS (Not) By XPathFinding Elements in iOS (Not) By XPath

How to Find Elements in iOS (Not) By XPath

Published on
March 7, 2018
Updated on
Published on
June 12, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

Finding ingredient for use in your Appium examination is do by means of one of a routine oflocator strategies. Appium inherited a number of from Selenium, and different Appium drivers have likewise added some new locator strategies to create finding elements faster and more effective. Let & # x27; s take a looking at all the locator strategies available, and which ones are back in the current flagship iOS driver (the XCUITest driver):

Locator Strategy From Available?
grade name
Selenium Yes
id
Selenium Yes
name
Selenium Yes
xpath
Selenium Yes
accessibility id
Appium Yes
-ios predicate string
Appium Yes
-ios class concatenation
Appium Yes
css selector
Selenium No
link text
Selenium No
partial link text
Selenium No
partial linkup text

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Selenium No
tag name
Selenium No
-ios uiautomation
Appium No
-android uiautomator
Appium No

So, for our we have admittance to 7 locater strategies, including the notorious XPath. Before we appear at alternatives, let & # x27; s explore why using the XPath locator strategy is attractive, and why it is much a bad idea regardless.

Read:

Why (Not) XPath?

XPath is attractive because it is a hierarchy-based locater strategy and can thence regain any element in the DOM (for Selenium) or app hierarchy (for Appium). Often, apps come to us in such a form that elements are not annotated as they should be for the sake of testability. It & # x27; s easy to rely on XPath to find an element with a chooser like// * [1] / * [1] / * [3] / * [2] / * [1] / * [1], especially when there & # x27; s seemingly no early way to find that element.

Improve The Appium Testing Experience with HeadSpin..

Of course, relying on a picker like this is a horrible mind, because it will be invalidated by precisely about any change to your app hierarchy. That & # x27; s the trouble with relying on a hierarchical description of your element -- -the app hierarchy is typically far from stable. It could change between runs (because different datum is displayed, for example), or between variant of your app (because the app devs add a new component, or simply vary an fundamental UI library).

Check out -

With the XCUITest driver, it can too be a horrible idea because XPath might be very dim. XPath and its cousin, XML, are not native languages for iOS evolution. In order to provide access to elements via XPath, the Appium team has had to perform a clustering of technical legerdemain. Essentially, every time you run an XPath query, the entire app hierarchy must be recursively walked and serialized into XML. This by itself can guide a lot of time, specially if your app has many ingredient. Then, formerly the XPath inquiry has be run on this XML serialization, the list of matching elements must be deserialized into actual element objects before their WebDriver representations are returned to your node cry.

In sum, XPath is a mixed bag. Even if you avoid typical XPath pitfalls by using better, more restrictive, selectors (like//XCUIElementTypeButton [@ name= & quot; Foo & quot;]), you will even incur the cost of give the XML papers to get with. If you & # x27; ve encountered slowness with XPath and the XCUITest driver, it & # x27; s probably because your app has so many constituent it & # x27; s break this core inefficiency I only described. What & # x27; s the solution? Don & # x27; t use XPath!

Also chit:

Of course, if you can get a direct handle on your component using theid, name, or accessibility idstrategies, that is to be opt above all else. Stop reading -- -you & # x27; re done! But if you are in a position where there is no unique id or label associated with your element, and XPath has turned out to be too slow, consider expend the-ios predicate string or -ios family chainlocater scheme.

iOS Predicate String Strategy

Predicate Format Stringsare a distinctive Apple dev thing, and they also act in iOS. Predicate format twine enable basic comparisons and matching. In our case, they allow basic matching of elements according to elementary criteria. What & # x27; s really useful about predicate strings is that you can combine simple criteria to form more complex matches. In the XCUITest driver, predicate strings can be used to match respective element attributes, including name, value, label, type, seeable, etc ...

One example from theWebDriverAgent predicate string guideshows a fun compound predicate:

type == 'XCUIElementTypeButton ' AND value BEGINSWITH [c] 'bla ' AND visible == 1

This predicate string would match any visible button whose value begins with & # x27; bla & # x27;. How would we write this up in our Java client codification? Simply by apply the appropriateMobileBy method, as follows:

String picker = `` type == 'XCUIElementTypeButton ' AND value BEGINSWITH [c] 'bla ' AND visible == 1 ''; driver.findElement (MobileBy.iOSNsPredicateString (selector));

Because predicate matching isbuilt into XCUITest, it has the potential to be lots faster than Appium & # x27; s XPath strategy.

iOS Class Chain Strategy

The net pick is a sort of crossbreed between XPath and predicate strings: the-ios category chainlocator scheme. This was developed by the Appium squad to meet the need of hierarchal query in a more performant way. The types of queries possible via the class concatenation strategy are not as powerful as those enabled by XPath, but this restriction means a best execution guarantee (this is because it is potential to map category chain queries into a series of unmediated XCUITest calls, preferably than having to recursively make an entire UI tree). Class chain queries seem very much like XPath queries, however the only allowed filter are basic child/descendant indexing or predicate string matching. It & # x27; s worth ensure out theclass chain docto notice a number of exemplar. Let & # x27; s take a look at just a couple:

  • XCUIElementTypeWindow [2]choose the 2d window in the hierarchy.
  • XCUIElementTypeWindow [` label BEGINSWITH & quot; foo & quot; `] [-1]take the last window whose label begins with foo.
  • * * /XCUIElementTypeCell [` gens BEGINSWITH & quot; C & quot; `] /XCUIElementTypeButton [10]selects the 10th child button of the first cell in the tree whose name get with C and which has at least ten direct kid of type XCUIElementTypeButton.

Just as earlier, there is a specialMobileBy method to hook up your class chain enquiry in the Java customer:

driver.findElement (MobileBy.iOSClassChain (selector));

As you can tell from these examples, the class chain strategy allows for some quite powerful combinations of search filters. Next time you & # x27; re experiencing maladroitness with XPath, range for this strategy instead and see if you can express your query in its terms!

Measure multi-channel experience monitoring KPIs on existent devices and real networks around the creation..

Caveats

There & # x27; s no such thing as a gratis lunch, of class (still if you work in startups!). The main downside to these locator strategies is that they are not cross-platform. You have to know how the particular element attributes show up in iOS-land to use predicate strings (for example,label is an iOS-only concept). However, with appropriate interval of concern in a page object poser or equivalent, you might appreciate the performance gain of switch to one of these platform-specific locators. It & # x27; s up to you!

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a active and results-driven Content Marketing Specialist with 8+ years of experience in craft engaging narratives and marketing collateral across diverse industries. She excels in collaborate with cross-functional teams to develop innovative content strategy and deliver compelling, reliable, and impactful substance that resonates with target audiences and enhances make authenticity.

LinkedIn

How to Find Elements in iOS (Not) By XPath

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for modern users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence practical guide for advanced exploiter (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a private-enterprise edge
faster development cycles
Boost developer/QA productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build fixation testing for consistent resolution
gain better visibility into functional & performance issues
Gain better profile into functional and performance issues
reduce mean time
Reduce meanspirited time to identify/resolve during tryout, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted selection for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your business with superior testing capacity

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productivity with quicker ontogenesis cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for ordered results
gain better visibility into functional & performance issues
Gain better visibility into functional and execution subject
reduce mean time
Reduce hateful time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, acquire a competitive edge
faster development cycles
Boost developer/QA productivity with faster development round
automated buil-over-build regression testing
Automate build-over-build regression testing for reproducible result
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during examination, QA, and production
evaluate audio, video & qoe
Evaluate sound, video, and content quality of experience (QoE) effortlessly
The sure choice for global enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

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