Two Objects have same Xpath?

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.

1 Like

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.

1 Like

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?

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

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 ?

1. I suggest finding a better xpath selector.

2. As a (hopefully temporarily) workaround, for the xpath ‘//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"]’ you can add (element number - 1), like in arrays:

//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) 

**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 ():

(//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]

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"…

//*[@class = ‘ng-star-inserted’ and @title = ‘ERASE’][2]

1 Like

@Normand Bourget

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

(//*[@class = ‘ng-star-inserted’ and @title = ‘ERASE’])[2]

1 Like

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)

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

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…

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’

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.

Did you try searching for //div[@title = ‘ERASE’][2] in DevTools?

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

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

DevTools???!?

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

$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.

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)

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

(//*[@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.

2 Likes