# Is there a way we can convert xpaths?

**URL:** <https://discuss.appium.io/t/is-there-a-way-we-can-convert-xpaths/13333>\
**Category:** Support\
**Created:** [November 17, 2016, 2:01pm UTC](https://discuss.appium.io/t/is-there-a-way-we-can-convert-xpaths/13333 "2016-11-17T14:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harikrishnaburma](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/2bfe46/32.png) [@harikrishnaburma](https://discuss.appium.io/u/harikrishnaburma)\
**Post date:** [November 17, 2016, 2:01pm UTC](https://discuss.appium.io/t/is-there-a-way-we-can-convert-xpaths/13333/1 "2016-11-17T14:01:31Z")

</div>

Appium 1.6.0

Is there a way to directly convert Xpaths in UIAAutomation framework to XCUITest framework?

---

<div class="post-metadata">

**Author:** ![Brian\_Watson](https://discuss.appium.io/user_avatar/discuss.appium.io/brian_watson/32/2664_2.png) [@Brian\_Watson](https://discuss.appium.io/u/Brian_Watson)\
**Post date:** [November 26, 2016, 3:12am UTC](https://discuss.appium.io/t/is-there-a-way-we-can-convert-xpaths/13333/2 "2016-11-26T03:12:09Z")

</div>

Currently, it looks like Appium 1.6.x does a pretty decent job of converting them for you. But, there were a few occasions where it didn’t work for me, and I wanted to retain compatibility with older version of iOS xpaths in my code still. So luckily, my appium framework is defined with a common class at it’s base for all controls. So I added a method to do the conversion that uses an ugly replace() action for xpaths and classNames…

```
private By convertForXCUITest(By iosLocator) {
    String[] parts = iosLocator.toString().split(": ");

    if (parts.length > 1) {
        String newValue = parts[1].
                replace("UIAStaticText", "XCUIElementTypeStaticText").
                replace("UIAButton", "XCUIElementTypeButton").
                replace("UIATableCell", "XCUIElementTypeCell").
                replace("UIANavigationBar", "XCUIElementTypeNavigationBar").
                replace("UIATextField", "XCUIElementTypeTextField").
                replace("UIAActivityIndicator", "XCUIElementTypeActivityIndicator").
                replace("UIASecureTextField", "XCUIElementTypeSecureTextField").
                replace("UIACollectionView", "XCUIElementTypeCollection").
                replace("UIACollectionCell", "XCUIElementTypeCell").
                trim();

        switch (parts[0]) {
            case "By.xpath":
                return By.xpath(newValue);

            case "By.className":
                return By.className(newValue);

            default:
                return iosLocator;
        }
    } else {
        return iosLocator;
    }
}
```

---

<div class="post-metadata">

**Author:** ![Mikhail\_Yesipchuk](https://discuss.appium.io/user_avatar/discuss.appium.io/mikhail_yesipchuk/32/14579_2.png) [@Mikhail\_Yesipchuk](https://discuss.appium.io/u/Mikhail_Yesipchuk)\
**Post date:** [October 16, 2026, 5:24pm UTC](https://discuss.appium.io/t/is-there-a-way-we-can-convert-xpaths/13333/3 "2026-10-16T17:24:48Z")

</div>

An update for anyone finding this thread now: UIAutomation is long gone, but the conversion question is still common. Today’s version is turning XPath locators into the faster `-ios class chain` strategy of the XCUITest driver.

There is now an open-source tool for that, which I wrote: xpath-to-class-chain. It scans your test code (JS/TS, Java, Kotlin, Python, Ruby, C#…), converts each XPath that has an exact class chain, warns on approximations, and skips the rest with a reason. It made no wrong chains on 678 real and edge-case locators checked against WDA’s own code, a simulator and an iPhone.

```bash
npx xpath-to-class-chain ./tests # preview the diff
npx xpath-to-class-chain ./tests --write # apply it

```

I also compared it with asking an LLM (Claude) to convert the same locators: [results](https://dev.to/mikhail_yesipchuk/xpath-to-ios-class-chain-can-claude-do-it-instead-of-a-converter-17m9).

GitHub: [GitHub - domovou69/xpath-to-class-chain: Convert and optimize XPath locators to iOS Class Chain selectors for Appium · GitHub](https://github.com/domovou69/xpath-to-class-chain)
