# Question: help to convert xpath query to class chain

**URL:** <https://discuss.appium.io/t/question-help-to-convert-xpath-query-to-class-chain/33694>\
**Category:** Support\
**Created:** [May 14, 2021, 1:15pm UTC](https://discuss.appium.io/t/question-help-to-convert-xpath-query-to-class-chain/33694 "2021-05-14T13:15:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_Duquia\_Giumelli](https://discuss.appium.io/user_avatar/discuss.appium.io/igor_duquia_giumelli/32/8391_2.png) [@Igor\_Duquia\_Giumelli](https://discuss.appium.io/u/Igor_Duquia_Giumelli)\
**Post date:** [May 14, 2021, 1:15pm UTC](https://discuss.appium.io/t/question-help-to-convert-xpath-query-to-class-chain/33694/1 "2021-05-14T13:15:52Z")

</div>

Hello

Is it possible to convert the following Xpath query to iOS class chain?

parentElement.findElement(  
By.xpath("(.//XCUIElementTypeCell[.//XCUIElementTypeOther//XCUIElementTypeOther//XCUIElementTypeOther])[last()]"))

tks

---

<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:21pm UTC](https://discuss.appium.io/t/question-help-to-convert-xpath-query-to-class-chain/33694/2 "2026-10-16T17:21:09Z")

</div>

For anyone landing here later: this one has no exact class chain, for two reasons.

1. `.//Other//Other//Other` inside the predicate is a nested path. Class chain predicates can test a descendant (`[$type == "XCUIElementTypeOther"$]`), but not a path of several descendants.
2. `(...)[last()]` is a position over all matches. WDA counts class chain matches breadth-first, XPath in document order, so `[-1]` can pick a different cell when the cells sit at different depths.

If the last cell is all you need, the closest chain is:

```java
parentElement.findElement(AppiumBy.iOSClassChain("**/XCUIElementTypeCell[-1]"));

```

Check it on the screen. A stable accessibility id on the cell is the better fix.

I built an open-source XPath to iOS class chain converter that makes this call for you: it converts what has an exact chain, warns on approximations like `[-1]`, and skips the rest with a reason. It runs over a whole test folder and prints a diff:

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

```

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)  
npm: [https://www.npmjs.com/package/xpath-to-class-chain](https://www.npmjs.com/package/xpath-to-class-chain)
