# Two Objects have same Xpath?

**URL:** <https://forum.katalon.com/t/two-objects-have-same-xpath/8713>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [January 3, 2018, 10:57am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713 "2018-01-03T10:57:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anh\_Tuan\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@Anh\_Tuan\_Nguyen](https://forum.katalon.com/u/Anh_Tuan_Nguyen)\
**Post date:** [January 3, 2018, 10:57am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/1 "2018-01-03T10:57:26Z")

</div>

When I capture 02 different objects (two input box), they have same Xpath and are appeared in a same object in Object Repository. So, I can input data in both of them with different data. Help me, plz.

---

<div class="post-metadata">

**Author:** ![Prithviraj\_Sahoo](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@Prithviraj\_Sahoo](https://forum.katalon.com/u/Prithviraj_Sahoo)\
**Post date:** [January 3, 2018, 11:47am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/2 "2018-01-03T11:47:50Z")

</div>

provide numbers to your xpath! For example if both text fields have //input[@id=‘something’] then you can edit the first field xpath as (//input[@id=‘something’])[1] and the second field’s xpath as (//input[@id=‘something’])[2] in object repository.

---

<div class="post-metadata">

**Author:** ![Jacqueline\_Flores](https://avatars.discourse-cdn.com/v4/letter/j/e19adc/32.png) [@Jacqueline\_Flores](https://forum.katalon.com/u/Jacqueline_Flores)\
**Post date:** [May 3, 2018, 10:23pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/3 "2018-05-03T22:23:07Z")

</div>

I don´t understand, I have two elements with same xpath and when I select the second one the program write the text in first one. How can I tell the program I want to write in the second one?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [May 3, 2018, 10:34pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/4 "2018-05-03T22:34:29Z")

</div>

Jacqueline,

Could you take screenshots and paste them here:  
1. HTML fragment of your two input boxes  
2. Your 1st Test Object (dont forget to include its xpath in the screenshot)  
3. Your 2nd Test Object as well

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [September 27, 2018, 8:45am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/5 "2018-09-27T08:45:33Z")

</div>

I have the same problem with this captured object by object spy :

Detect object by :

tag equals span (Detect object by = yes)

class equals fa fa-trash fa-lg (Detect object by = yes)

xpath equals id(“ui-accordiontab-5-content”)/div[@class=“ui-accordion-content ui-widget-content ng-tns-c39-9 ng-star-inserted”]/display-localisation[1]/div[@class=“img-container”]/a[@class=“ng-star-inserted”]/span[@class=“fa fa-trash fa-lg”] (Detect object by = no)

How can I tell object repository to select the 2nd element found with those properties please ?

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [September 27, 2018, 9:09am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/6 "2018-09-27T09:09:07Z")

</div>

1. I suggest finding a better xpath selector.

2. As a (hopefully temporarily) workaround, for the xpath ‘//id(“ui-accordiontab-5-content”)/div[[@content](http://forum.katalon.com/profile//content) ui-widget-content ng-tns-c39-9 ng-star-inserted"]/display-localisation[1]/div[[@container"]/a[](http://forum.katalon.com/profile//container%22%5D%2Fa%5B)[@inserted"]/span[](http://forum.katalon.com/profile//inserted%22%5D%2Fspan%5B "Link: http://forum.katalon.com/profile//inserted%22%5D%2Fspan%5B")[@class="fa](http://forum.katalon.com/profile//class%3D%22fa) fa-trash fa-lg"]’ you can add (element number - 1), like in arrays:

```auto
//id("ui-accordiontab-5-content")/div[@content ui-widget-content ng-tns-c39-9 ng-star-inserted"]/display-localisation[1]/div[@container"]/a[@inserted"]/span[@class="fa fa-trash fa-lg"](1) 

```

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [September 27, 2018, 9:14am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/7 "2018-09-27T09:14:10Z")

</div>

\*\*EDIT \*\*(because I am unable to edit my own answer):

The array element should go inside of [] instead of (), and the whole xpath expression should go inside of ():

```auto
(//id("ui-accordiontab-5-content")/div[@content ui-widget-content ng-tns-c39-9 ng-star-inserted"]/display-localisation[1]/div[@container"]/a[@inserted"]/span[@class="fa fa-trash fa-lg"])[1]

```

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [September 27, 2018, 2:08pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/8 "2018-09-27T14:08:40Z")

</div>

Thanks.

I can’t work on this test rigth now but I tried your solution on another one.

I tried (//\*([@class = ‘ng-star-inserted’ and @title = ‘ERASE’][2]) but I get "

not a valid XPath expression"…

---

<div class="post-metadata">

**Author:** ![Trong\_Bui](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/trong_bui/32/374_2.png) [@Trong\_Bui](https://forum.katalon.com/u/Trong_Bui)\
**Post date:** [September 28, 2018, 4:42am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/9 "2018-09-28T04:42:32Z")

</div>

//\*[[@class](http://forum.katalon.com/profile//class "Link: http://forum.katalon.com/profile//class") = ‘ng-star-inserted’ and [@title](http://forum.katalon.com/profile//title "Link: http://forum.katalon.com/profile//title") = ‘ERASE’][2]

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [September 28, 2018, 6:12am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/10 "2018-09-28T06:12:09Z")

</div>

@Normand Bourget

You have an extra “(”. Try Trong Bui’s solution or:

(//\*[[@class](http://forum.katalon.com/profile//class "Link: http://forum.katalon.com/profile//class") = ‘ng-star-inserted’ and [@title](http://forum.katalon.com/profile//title) = ‘ERASE’])[2]

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [September 28, 2018, 2:50pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/11 "2018-09-28T14:50:23Z")

</div>

Thks, I don’t have a syntax error anymore.

But even if Katalon can finds 2 elements, it still can’t select 2nd element (I simplified my XPATH for this example) :

09-28-2018 04:39:00 PM - [INFO] - Finding web element with id: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’ located by ‘By.xpath:  
//\*[@title = ‘ERASE’]’ in ‘30’ second(s)

09-28-2018 04:39:00 PM - [INFO] - Found 2 web elements with id: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’ located by ‘By.xpath:  
//\*[@title = ‘ERASE’]’ in ‘30’ second(s)

09-28-2018 04:39:00 PM - [INFO] - Clicking on object: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’

09-28-2018 04:39:00 PM - [PASSED] - Object: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’ is clicked on

09-28-2018 04:39:00 PM - [END] - End action : click

09-28-2018 04:39:00 PM - [START] - Start action : click

09-28-2018 04:39:00 PM - [INFO] - Finding Test Object with id ‘Object  
Repository/Socle/GSCP/socleLocalisationPointErase’

09-28-2018 04:39:00 PM - [INFO] - Checking object

09-28-2018 04:39:00 PM - [INFO] - Checking timeout

09-28-2018 04:39:00 PM - [INFO] - Finding web element with id: ‘Object  
Repository/Socle/GSCP/socleLocalisationPointErase’ located by ‘By.xpath:  
//\*[@title = ‘ERASE’][2]’ in ‘30’ second(s)

09-28-2018 04:39:31 PM - [FAILED] - Unable to click on  
object ‘Object Repository/Socle/GSCP/socleLocalisationPointErase’ (Root cause:  
com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element  
with id: ‘Object Repository/Socle/GSCP/socleLocalisationPointErase’ located by  
‘By.xpath: //\*[@title = ‘ERASE’][2]’ not found)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 28, 2018, 3:18pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/12 "2018-09-28T15:18:58Z")

</div>

Can you replace `*` in  
`//*[@title = 'ERASE'][2]`  
to concrete element name such as  
`//div[@title = 'ERASE'][2]`  
?

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [September 28, 2018, 3:41pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/13 "2018-09-28T15:41:25Z")

</div>

> [kazurayam](https://forum.katalon.com/profile/4280/kazurayam) said:
> 
> Can you replace `*` in  
> `//*[@title = 'ERASE'][2]`  
> to concrete element name such as  
> `//div[@title = 'ERASE'][2]`  
> ?

Still can’t find 2nd element…

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 28, 2018, 9:28pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/14 "2018-09-28T21:28:51Z")

</div>

Strange. I need to reproduce your problem and work on it. Could you provided …

(0) version of your Katalon Studio

(1) full HTML source code of the target HTML, attach the text file here

(2) screen shot of the test object ‘Object Repository/Socle/socleLocalisationAdresseErase’

(3) screen shot of the test object ‘Object Repository/Socle/GSCP/socleLocalisationPointErase’

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [October 5, 2018, 9:46am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/15 "2018-10-05T09:46:58Z")

</div>

Sorry but I’m not legally allowed to provide HTML source out  
of office…

Katalon version is 5.6

How can I provid screen shots here ?

Anyway, below the 2 objects :

SocleLocalisationAdresseErase is xpath equals //\*[@title =  
‘ERASE’]

SocleLocalisationPointErase is either xpath equals  
//\*[@title = ‘ERASE’][2] or xpath equals //div[@title = ‘ERASE’][2] (I tried both  
but same result : not found)

Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [October 5, 2018, 10:10am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/16 "2018-10-05T10:10:52Z")

</div>

Did you try searching for //div[[@title](http://forum.katalon.com/profile//title) = ‘ERASE’][2] in DevTools?

Enter this to the console and see if the element is found:

```auto
$x("//div[@title = 'ERASE'][2]")

```

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [October 5, 2018, 10:16am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/17 "2018-10-05T10:16:35Z")

</div>

**DevTools???!?**

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [October 5, 2018, 10:44am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/18 "2018-10-05T10:44:29Z")

</div>

(In Chrome)  
Open browser on the page you are testing. Press F12 -\> DevTools will show up.  
Go to the “Console” tab and enter

```auto
$x("//div[@title = 'ERASE'][2]")

```

If the xpath is correct, and the element is present on page, the div with title “erase” should be highlited.

---

<div class="post-metadata">

**Author:** ![Normand\_Bourget](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@Normand\_Bourget](https://forum.katalon.com/u/Normand_Bourget)\
**Post date:** [October 5, 2018, 12:47pm UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/19 "2018-10-05T12:47:01Z")

</div>

The results (and more tests) :

$x("//div[@title = ‘ERASE’]")

[]

$x("//div[@title = ‘ERASE’][2]")

[]

$x("//\*[@title = ‘ERASE’]")

(2) [a.ng-star-inserted, a.ng-star-inserted]

$x("//\*[@title = ‘ERASE’][2]")

[]

$x("//_[@title = ‘ERASE’][1]")  
(2) [a.ng-star-inserted, a.ng-star-inserted]  
$x("//_[@title = ‘ERASE’][last()]")  
(2) [a.ng-star-inserted, a.ng-star-inserted]  
$x("//_[@title = ‘ERASE’][position()=1]")  
(2) [a.ng-star-inserted, a.ng-star-inserted]  
$x("//_[@title = ‘ERASE’][position()=2]")  
[]

So the question remains : why Katalon can find 2 elements  
but can’t find the 2nd one separately ??

09-28-2018 04:39:00 PM - [INFO] - Finding web element with id: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’ located by ‘By.xpath:  
//_[@title = ‘ERASE’]’ in ‘30’ second(s)09-28-2018 04:39:00 PM - [INFO] - Found 2 web elements with id: ‘Object  
Repository/Socle/socleLocalisationAdresseErase’ located by 'By.xpath:  
//_[@title = ‘ERASE’]’ in ‘30’ second(s)

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [October 9, 2018, 6:27am UTC](https://forum.katalon.com/t/two-objects-have-same-xpath/8713/20 "2018-10-09T06:27:42Z")

</div>

Katalon can select only the second. This is how it worked for me:

```auto
(//*[@class = 'ng-star-inserted' and @title = 'ERASE'])[last()]

```

Note: this is not the DevTools but I wrote this as a xpath selector in the Object Repository. The braces () are around the xpath and the [last()] part is added later. Try this, please.

[Next page](https://forum.katalon.com/t/two-objects-have-same-xpath/8713.md?page=2)
