# Two object have same Xpath in iOS

**URL:** <https://forum.katalon.com/t/two-object-have-same-xpath-in-ios/36014>\
**Category:** Mobile Testing\
**Tags:** mobile-testing, katalon-studio\
**Created:** [November 8, 2019, 9:50am UTC](https://forum.katalon.com/t/two-object-have-same-xpath-in-ios/36014 "2019-11-08T09:50:24Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Chris\_Trevarthen](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/chris_trevarthen/32/358_2.png) [@Chris\_Trevarthen](https://forum.katalon.com/u/Chris_Trevarthen)\
**Post date:** [November 9, 2019, 3:24am UTC](https://forum.katalon.com/t/two-object-have-same-xpath-in-ios/36014/4 "2019-11-09T03:24:30Z")

</div>

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:

> [@Unable to click/tap on a button in Android WebView](http://forum.katalon.com/t/unable-to-click-tap-on-a-button-in-android-webview/20135/7):
>
> Hi @Sravya_Batchu, That’s a lot of good information, thank you! I’m curious what Katalon and Appium think are on the screen at the time you switch to the WebView. If you want to see some more detail about exactly what Appium/Katalon detects on the screen you can log out the XML contents of the screen. You should be able to do that by putting the following import statements at the top of your test case: import com.kms.katalon.core.logging.KeywordLogger import com.kms.katalon.core.mobile.keywor…

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](https://www.freeformatter.com/xpath-tester.html)

Hope this helps,

Chris

---

_[View the full topic](https://forum.katalon.com/t/two-object-have-same-xpath-in-ios/36014)._
