Hi Ranorex Support team,
Even it's not the best solution, the best way we found to recognize our application windows to base it on the instance number.
A few weeks ago, i have recorded several scenarios with elements organized as follow : The main window (instance 0) that contains a window A (instance 0), a window B (instance 1) and a window C (instance 2).
The scenarios replay has worked well several days without problems. Today, the replay of the scenario does not work because the order of instance number associated to each windows has changed : The main window (instance 0) that contains a window A (instance 2), a window B (instance 1) and a window C (instance 0).
Is it a bug ? if not, the instance number associated to each element is aleatory ? It there a way to constrain the instance number associated to each element (maybe with a rule to added in a plugin file) ?
Thank you in advance,
Florent
Changing of instance number associated to elements
Re: Changing of instance number associated to elements
The instance number is automatically generated based on which element gets created first, second, third, etc... Instance number is very likely to break and should not be relied upon as your unique identifier for your elements.
You need to examine your AUT and determine what the best, static, unique identifier is in your AUT. If there are none and the instance ID is it then you should talk with your dev team about properly naming the elements in the AUT.
You need to examine your AUT and determine what the best, static, unique identifier is in your AUT. If there are none and the instance ID is it then you should talk with your dev team about properly naming the elements in the AUT.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Changing of instance number associated to elements
Well, this is not entirely correct. The instance is automatically computed and differentiates native windows with the same classname, true. However, its value is based on the x/y location of the window (geometry: left before right, top before bottom), not on the order of creation. Otherwise it would be the same as the ordinary index in RanoreXPath (in other words, the order of creation for windows determines the order of siblings in the Ranorex element tree).Ciege wrote:The instance number is automatically generated based on which element gets created first, second, third, etc...
Anyway, you are right, the "instance" number is not a very reliable identifier and is only used in RanoreXPaths if there is no other attribute to differentiate native windows. However, for RanoreXPaths of repository folders or if the "instance" is not used to determine the last element in a RanoreXPath, it can be beneficial to remove the "instance". For example:
Code: Select all
/form/container[@instance='5']/button[@controlname='MyButton']
--> /form/container/button[@controlname='MyButton']
Currently, Ranorex by default generates RanoreXPaths that try to identify every level in a RanoreXPath uniquely, that's why the "instance" numbers are there sometimes. We are currently evaluating ways to improve the RanoreXPath generation algorithm for cases where a less distinct identification for "container" elements can improve the stability of RanoreXPaths (like in the above example).
Regards,
Alex
Ranorex Team
Re: Changing of instance number associated to elements
Thanks for clearing up the details. I guess I was a little loose with my understanding of how the internals work...Support Team wrote: Well, this is not entirely correct.

If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Changing of instance number associated to elements
You are welcome! Your explanations were almost correct - actually, the instance number worked exactly as you explained in Ranorex 1.XCiege wrote:Thanks for clearing up the details. I guess I was a little loose with my understanding of how the internals work...

Regards,
Alex
Ranorex Team
Re: Changing of instance number associated to elements
Many thanks for all those details Ciege and Support team
I have the possibility to choose another property to identify the elements but the number of instance simplified the work. Indeed, in the past, i chose a unique identifier for each window : the window title. It worked well but there is the current date and others variables text in my windows titles. So after each recording, i have to remove the variable part from the title in the RanoreXPaths recorded in the repository. It's quite boring. Otherwise, a scenario recorded today does not work tomorrow.
Is there a solution, a Ranorex plugin, to do this repetitive work automatically ?
A rule to add in the "Editing Path weights" form ?
On the other hand, when i base the recognition on the instance number, i have 1 repository item for the same button ( for example, a "validate" button) in 2 windows with differents titles but the same instance number. So my repository did not grew too much.
If it's not possible, i will come back to the old way of work...
see you soon
I have the possibility to choose another property to identify the elements but the number of instance simplified the work. Indeed, in the past, i chose a unique identifier for each window : the window title. It worked well but there is the current date and others variables text in my windows titles. So after each recording, i have to remove the variable part from the title in the RanoreXPaths recorded in the repository. It's quite boring. Otherwise, a scenario recorded today does not work tomorrow.
Is there a solution, a Ranorex plugin, to do this repetitive work automatically ?
A rule to add in the "Editing Path weights" form ?
On the other hand, when i base the recognition on the instance number, i have 1 repository item for the same button ( for example, a "validate" button) in 2 windows with differents titles but the same instance number. So my repository did not grew too much.
If it's not possible, i will come back to the old way of work...
see you soon
Re: Changing of instance number associated to elements
You can easily "ignore" the date in the window titles by using a RegEx in your XPath.
Have a read here: http://www.ranorex.com/support/user-gui ... html#c3294
Have a read here: http://www.ranorex.com/support/user-gui ... html#c3294
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Changing of instance number associated to elements
Thank you Ciege
with all those elements, i'm in a good way to find a solution
i'll tell you
see you soon
with all those elements, i'm in a good way to find a solution
i'll tell you
see you soon