Record with only XPath

While recording a test case want the katalon studio to record the elements as XPath alone like what we get in google chrome :

Recorded XPath by katalon :

/html[1]/body[1]/div[3]/div[2]/div[1]/div[1]/div[@class=“root-panel”]/div[5]/div[@class=“plain-border”]/div[3]/div[@class=“gwt-TabLayoutPanel”]

/div[3]/div[@class=“gwt-TabLayoutPanelContentContainer”]/div[3]/div[@class=“gwt-TabLayoutPanelContent”]/div[2]/div[@class=“gwt-SplitLayoutPanel”]

/div[2]/div[@class=“rounded-border”]/div[4]/div[@class=“gwt-Label label-hyperlink”]

But when i right click and copy xpath of an html element via chrome i get this :

/html/body/div[2]/div[2]/div/div/div/div[5]/div/div[3]/div/div[3]/div/div[3]/div/div[2]/div/div[2]/div/div[4]/div

The one I get along with chrome is always correct but the one I get with the katalon studio is not right always.

How do I solve it?

How about copying the xpath generated by chrome and pasting it into the Katalon? :stuck_out_tongue:
I do it quite often. And I always edit the pasted one. Even the xpath generated by chrome tends to be verbose. I always enjoy trying to find the shortest but readable xpath.

Out of interest, is xpath the only method that works for your app? Your example from Chrome looks like it would break at the first code change.

Dan,

I take your point. I would reword mine:

… tends to be fragile against HTML change.I always enjoy trying to find the shortest and robust xpath against change in the target HTML.

neither of them is good: with a small change to page both will stop working
to construct good xpath, you need to think about it - here are rules i use:
1. KISS - Keep It Simple - Stupid! - shorter xpath -better xpath - more resilient to changes on page
2. start looking for xpath from end - i know what i want to get, so i start looking for nearest addressable component - with id/class/other unique attributes or text()
3. avoid use of n-th element ([n]) in xpath if possible - this is what can change even by page itself (by javascript)
in you case will be something like:

//div[contains(@class,'border')]//div[contains(@Label,'label-hyperlink')]

i’m not sure about attributes since this editor likes to screw those up and it seems it does it in your post too

1 Like

damn standups … as allways @4280-kazurayam was faster :wink:

Use chro path Google extension and capture relative x path add that into katalon object works really well for me

My Webpage is made of GWT and we dont define textboxes or other elements by ids we use only classes throughout so xpath is the only way to target the element. Or is there an another way ?

@4280-kazurayam As you said copying xpath from chrome works always but i dont want to do it as it takes a huge time.

My Problem is if you see closely xpath generated by Katalan and chrome it differs

Katalon : /html[1]/body[1]/div[3]/div[2]/
Chrome : /html/body/div[2]/div[2]/

Katalon says div[3] and chrome says div[2]. Why this difference comes ?

@Andrej Podhajský I cannot use it in reverse. As i said before my html elements are defined as classes not by ids.

@Dan Bown Unfortunately yes, as my html elements are defined as classes not by ids.

Vijay,
you can use classes also in xpath … see my post
about reverse - it’s technique, way how you can construct shortest unique xpath for your element…
please, take a look at https://www.w3schools.com/xml/xpath_intro.asp to get more ideas
there are many ways how to use xpath to get what you want …

Katalon says div[3] and chrome says div[2]. Why this difference comes ?

Please show the target HTML here. Without it, I can not see anything.

Or it can be a case that the target Web page is dynamically updated by JavaScript, so that the generated xpath can differ depending on the timing when you capture it. I mean, choice of katalon & chrome may not be the issue. Capturing xpath (or css selector) by tools depends on the status of target HTML. If the HTML is of dynamic nature, then generating xpath for it becomes a tough task.

1 Like

@4280-kazurayam As you said copying xpath from chrome works always but i dont want to do it as it takes a huge time.

Time you invest in definition of object will return to you as time saved during test maintenance.

carefully defined objects can save you lot of time, so it pays of in long run to invest time during their definition.

in awfully coded web pages that does not care about QA (no identifier of objects whatsoever) it’s hard to record objects in proper way - you need to define them by yourself

1 Like

@Andrej Podhajský But can we automate it with katalon studio? The person who gonna record test case has no programming knowledge. So it would be better if katalon does the job for me.

Vijay Vignesh said:

@Andrej Podhajský But can we automate it with katalon studio? The person who gonna record test case has no programming knowledge. So it would be better if katalon does the job for me.

You can let this person to record TC but you will need someone to dig into recorded scripts to make them work.

1 Like

@4280-kazurayam and @Andrej Podhajský Got it, guys. Will figure out an easy and efficient way to capture XPath by some browser tools and get it done.

Bon voyage!

hi kazurayam , can u help me how to paste the xpath in katalon generated by chrome , where exactly that xpath should be pasted in katalon , thank you

in OR

1 Like