Hello
Is it possible to convert the following Xpath query to iOS class chain?
parentElement.findElement(
By.xpath("(.//XCUIElementTypeCell[.//XCUIElementTypeOther//XCUIElementTypeOther//XCUIElementTypeOther])[last()]"))
tks
Hello
Is it possible to convert the following Xpath query to iOS class chain?
parentElement.findElement(
By.xpath("(.//XCUIElementTypeCell[.//XCUIElementTypeOther//XCUIElementTypeOther//XCUIElementTypeOther])[last()]"))
tks
For anyone landing here later: this one has no exact class chain, for two reasons.
.//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.(...)[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:
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:
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
npm: https://www.npmjs.com/package/xpath-to-class-chain