Two object have same Xpath in iOS

Hi @fap,

As far as I know, it’s not really possible for 2 objects on the same screen to have the same full xpath. They may share most of the xpath, but at the end, they will have a different index. So, in your example above, it would be something like this:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeScrollView[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][count(. | //*[@type = 'XCUIElementTypeTextField']) = count(//*[@type = 'XCUIElementTypeTextField'])][1]

and

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeScrollView[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][count(. | //*[@type = 'XCUIElementTypeTextField']) = count(//*[@type = 'XCUIElementTypeTextField'])][2]

I will say that your xpath above seems very complicated and is likely to break if even a small change to the layout occurs. In my tests, I try to make the xpath simple as possible by giving each element its own accessibility id in Xcode and then using that as the name attribute for the Test Object.

If you don’t have access to make a change to assign accessibility ids, then you can at least try to simplify the xpath by capturing the entire contents of the screen as XML. See this post for how to do that:

Then you can play around with the xpath to find a simpler one that works for you using Free Online XPath Tester / Evaluator - FreeFormatter.com

Hope this helps,

Chris