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.
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.
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"ā¦
@Normand Bourget
You have an extra ā(ā. Try Trong Buiās solution or:
(//*[@class = āng-star-insertedā and @title = āERASEā])[2]
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.