Ranorex xpath format

Ask general questions here.
c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Ranorex xpath format

Post by c676228 » Fri May 08, 2015 12:43 am

Hi Folks,

I just noticed that xpath sometimes using CSS style path during recording.
For example, the xpath could be .//span[#'someid']
sometimes it could be .//span[id='someid']
In the first scenario, if you want to do .//span[#'someid' and @attribute='123'], it won't allow you apply the update.
you have to use .//span[id='someid' and @attribute='123']

Do I need to use one form of xpath or just leave as they are?

Comments? suggestions?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Ranorex xpath format

Post by odklizec » Fri May 08, 2015 7:07 am

Hi,

#'someid means "unique id". If unique id is used and you still want to use also another attribues then the path must be like this...
.//span[#'someid'][@attribute='123']

Check this page with xpath examples...
http://www.ranorex.com/support/user-gui ... xpath.html
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex xpath format

Post by krstcs » Fri May 08, 2015 1:25 pm

The point of a unique ID ('#') is that it should uniquely identify only one element on the page/form. There should be no need for any other attributes in order to identify the element (which is why Ranorex Studio won't let you update the XPath if you are using '#'). If your unique id is not unique then it will default to the second form (@id=).
Shortcuts usually aren't...

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: Ranorex xpath format

Post by c676228 » Fri May 08, 2015 5:00 pm

Hi krstcs/odklizec,

Thank you both for the comments. The xpath examples are from my recording.
I didn't specifically choose # or @id format.

The UI element with # is unique. However, the innertext is created dynamically for this unique UI element and will only display when there is an error. So I need to use another attribute innertext to identify the actual issue of the application.

During the remote session we try to use .//span[@id='useremail-error-msg' and @visible='True' and innertext='different error message'] to identify this dynamic message. It is failed.
So we have to go back to .//span[@id='useremail-error-msg' and @visible='True'].

This doesn't solve the problem since I don't know the exact error message.
Any comments?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex xpath format

Post by krstcs » Fri May 08, 2015 5:27 pm

My understanding is that you want to retrieve and validate the innertext of the element with the unique id. Is that correct?

But, you have the difficulty that the innertext is not actually available until the element becomes visible. Is that also correct?

My suggestion would be to use a variable in your module that you would put the value of the innertext in and then validate that value against the expected result. You would use the GetValue method on the innertext attribute of the element AFTER you mouse-over, click, etc., to make the element appear.
Shortcuts usually aren't...

c676228
Posts: 176
Joined: Mon Apr 06, 2015 5:40 am

Re: Ranorex xpath format

Post by c676228 » Fri May 08, 2015 8:35 pm

Hi krstcs,

Yes to both of your questions.

I think you made a point here. Actually the innertext can be identified in the program as I noticed when I did validate in the user code.

The innertext is like a tooltip, if you click anywhere else on the page, or open another a tab in the browser, or open Ranorex Spy. The innertext is gone.I guess this is why Ranorex Spy cannot identify it?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Ranorex xpath format

Post by krstcs » Fri May 08, 2015 9:38 pm

That is probably correct. The issue in cases like these is usually that spy can't find a parent container of the element and, therefore, can't find the actual element, even though the information is all in the HTML or script. You will probably want to force the element to appear every time you try to validate it, just to make sure you get it the way a user would.
Shortcuts usually aren't...