# Issue with two objects with the same XPATH and attributes

**URL:** <https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028>\
**Category:** Mobile Testing\
**Tags:** mobile-testing, katalon-studio\
**Created:** [June 23, 2021, 3:17pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028 "2021-06-23T15:17:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [June 23, 2021, 3:17pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/1 "2021-06-23T15:17:13Z")

</div>

Hi,

I am performing UI automation with IOS simulator on a mobile app. I came across an issue with the login text fields having identical object attributes as well as path and when setting text in the fields it sets the text in the same field to no surprise. Is there a fix/workaround for this? Please see below the object attributes. Thanks.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/2/e/2ef5afcb2b899c74a82080c290da1b371b7ef9db.jpeg)

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/7/a/7ae62d111bf087368244f3cd98d7d7f5bcf906d3.jpeg)

Note that I have tried using the other object attributes but the objects are not found when I run the script. With this issue, we cannot automate the mobile app login.

Katalon Studio: 8.0.5  
IOS 14.5

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [June 24, 2021, 9:59am UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/2 "2021-06-24T09:59:21Z")

</div>

Hello,  
usually you can add array index in case xpath returns more than 1 element:

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/a/e/ae42be02a9e10d9503203dbd3e860845dcbf35a9.png)

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [June 25, 2021, 1:17pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/3 "2021-06-25T13:17:58Z")

</div>

Hi Andrej,

I’m not sure I follow your solution. In my case both XPATHs are exactly the same.

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [June 25, 2021, 1:34pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/4 "2021-06-25T13:34:06Z")

</div>

imagine following path:

```auto
//input[@attribute='value1']

```

this xpath will return 2 objects ( 2 input fields with same xpath)  
to distinguish between them, use array notation to adress either 1st or 2nd of them:

```auto
(//input[@attribute='value1'])[1]

```

for 1st resp.

```auto
(//input[@attribute='value1'])[2]

```

for 2nd element

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [June 25, 2021, 1:53pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/5 "2021-06-25T13:53:24Z")

</div>

hi Andrej,

By the way, this is with Mobile, not Web.  
This is what the XPATHS look like for the 2 objects:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]

So how can I select a specific object with this XPATH? Do I need to make changes to the XPATH in the object repository as shown below?

object 1:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][1]

object 2:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][2]

And then how do I setText for these objects using scripting?

Thanks.

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [June 25, 2021, 2:16pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/6 "2021-06-25T14:16:26Z")

</div>

> [@mgrandillo](#):
>
> object 1:  
> /XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][1]  
> object 2:  
> /XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][2]

cant you use those paths? that is wat i was refering to

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [June 25, 2021, 2:35pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/7 "2021-06-25T14:35:42Z")

</div>

When I changed the objects in the object repository to this:

object 1:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][1]

object 2:

//XCUIElementTypeApplication/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeTextField[1][2]

And use this command line to set the text in the respective fields:

Mobile.setText(findTestObject(‘Object Repository/Login Screen/IOS/XCUIElementTypeTextField - Locator Service URL’), locatorService, 30)

Mobile.setEncryptedText(findTestObject(‘Object Repository/Login Screen/IOS/XCUIElementTypeTextField - Email’), username, 30)

**Result:** The locatorService text and username text is set in the same field.

Is the problem in the scripting? Or there is something I need to change in the Object Repository for those objects? Thanks.

---

<div class="post-metadata">

**Author:** ![mgrandillo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mgrandillo/32/16104_2.png) [@mgrandillo](https://forum.katalon.com/u/mgrandillo)\
**Post date:** [June 25, 2021, 2:50pm UTC](https://forum.katalon.com/t/issue-with-two-objects-with-the-same-xpath-and-attributes/56028/8 "2021-06-25T14:50:38Z")

</div>

Ok I got it to work it seems. I will run more tests to confirm. Thanks for your help!
