ranorex spy unique id setting

Ask general questions here.
martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

ranorex spy unique id setting

Post by martinsw » Tue Aug 14, 2012 2:34 pm

Hi,

Since Ranorex 3.3 was released, Ranorex spy can now search for elements based on their unique id (when the spy setting is enabled).

E.g. .//span[#'PageLayout_lblSelectUserTitle']

Please can you advise, how should I write the Ranorex path for the element above if I want to add additional attributes for this element, such as validating its innertext value. The following is not valid syntax:

.//span[#'PageLayout_lblSelectUserTitle' and @innertext~'Fred']

so I have been using the following approach

.//span[#'PageLayout_lblSelectUserTitle']/../span @innertext~'Fred']

Is this the best/most efficient way to do it?

Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: ranorex spy unique id setting

Post by Support Team » Thu Aug 16, 2012 9:20 am

Hello,

The unique id for an HTML element should be unique within the HTML document. That's why the path .//span[#'PageLayout_lblSelectUserTitle' and @innertext~'Fred'] would make no sense and is not supported by the RxPath. If your id's are not unique you should not use the unique id search because you would get problems with finding elements and executing your tests.
What is the reason for doing that?

Regards,
Bernhard
Ranorex Support Team
.
Image

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: ranorex spy unique id setting

Post by martinsw » Thu Aug 16, 2012 1:04 pm

Hi Bernard,

IMaybe I'm not fully understanding what the search by unique id feature is actually doing.

Let me give you an example of what I am trying to achieve and then maybe any misunderstandings that I have will become clearer to you and you can put me right.

Attached is a snapshot of a label within my application. The innertext attribute of this label is "Business Partner" and the id attribute has a value of 'PageLayout_lblBusinessPartner'. The attached screenshot shows the appearance of this label within my application.

When I search for the element in spy, with the unique id attribute switched on, the returned path is "//span[#'PageLayout_lblBusinessPartner']".

I want to search by unique id as it keeps my xpaths shorter and speeds up my tests. However, I also want to validate the elements existence based on the fact that its id attribute matches the unique id and its innertext attribute has a value of "Business Partner". Please can you tell me how I should write an xpath that does this?

If I am not asking a valid question please can you explain why it is not valid?

Thanks.
Attachments
screenshot.jpg
screenshot.jpg (16.38 KiB) Viewed 1075 times
BusinessPartner.rxsnp
(228.13 KiB) Downloaded 143 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: ranorex spy unique id setting

Post by Support Team » Fri Aug 17, 2012 9:18 am

Hello,

Thank you for describing your issue.
The use of relations in the RxPath when you use the uniqueId search is not directly supported in Ranorex to use, but there are two workarounds to handle this.

//span[@id='PageLayout_lblBusinessPartner' and @innertext='Business Partner:']
It should not be much slower than the uniqueId search.

The following path describes a AND relation between the uniqueid and the innertext attribute.
//span[#'PageLayout_lblBusinessPartner'][@innertext='Business Partner:']

Regards,
Bernhard
Ranorex Support Team
.
Image

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: ranorex spy unique id setting

Post by martinsw » Fri Aug 17, 2012 11:53 am

Thanks Bernhard!