Page 1 of 1

How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 2:56 pm
by mghali
In my tests I need to recognize a patients name, but when i record the test the patients name chosen based on the position of the name, and not the name it self.

for example: It chooses row 8 and not patient name william.

How can I work around this?

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 3:30 pm
by krstcs
Without more detailed information it will be hard to understand your issue.

Please answer the following questions:
1. What version of Ranorex are you using?
2. Can you provide a snapshot of the elements in question? (See the following link for information on creating a Ranorex Snapshot: http://www.ranorex.com/support/user-gui ... files.html)
3. What technology is your application-under-test (AUT) created in? (.NET, WPF, Silverlight, Java, WEB/HTML, etc.)
4. What operating system and bitness (32/64-bit) are you using?
5. Can you provide the XPath that you are using to identify the element in question?

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 4:59 pm
by mghali
1. I am using 4.1

2. I got error for snapshots so here is a screen shot. I need to select the element highlighted, at position Row 93. This is subject to change on a daily basis. So my selection criteria should be the name (whatsoever might the position be).



3.It is created in .NEt and C#

4. 64 bit

5. X pathP: row[@accessiblename='Row 93']/cell[@accessiblename='Patient Name Row 93']

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 5:18 pm
by krstcs
OK, with spy, you should be able to see that the cell actually has a TEXT attribute. If you use that in your path it should work.

Try this path: "row/cell[@text=$PatientName]" (without quotes)

We don't actually care about the row, we just want the row that contains the cell with that name. You can add each cell that you need to use in identifying the row by using the "/parent::row/cell[@text=$DOB]" format. Add it to the end of the current path for each cell you want to use.

Also, since you have mixed-case you can change the path to the following as a Regular Expression (RegEx): "row/cell[@text~'(?i:' + $PatientName + ')'" (without quotes). This will make it ignore case, but the letters, spaces and punctuation must still match.



Also, if the information contained in that screenshot is test info, then no worries. If it is real live information for real people, please delete it immediately. I would hate for the information to be misused. :D

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 5:40 pm
by mghali
My next question would be, will this work even if the name is not visible on the screen? I mean will it scroll to the name which is alphabetically placed close to the end of the list

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 6:41 pm
by krstcs
It SHOULD. Sometimes the scrolling is a bit finicky. If it doesn't automatically scroll, you can try putting in an EnsureVisible action right before your click, it might help. EnsureVisible is under the Invoke Action menu item.

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 7:23 pm
by mghali
Hey Thank you for all the help.

The error i get is this: Failed to move to location 'Center' within element '{Cell:Patient Name Row 93}'.
The pointer cannot be moved to point '{X=358,Y=2232}' since it is outside of the visible desktop


It cannot scroll to the patient name

Re: How to identify object based on their name and not position

Posted: Wed Aug 06, 2014 8:28 pm
by krstcs
You're welcome!

Did you try putting an EnsureVisible step right before the click?

Drag the repository object for the cell up into the action table. In the menu that pops up, mouse-over "Invoke Action" and select EnsureVisible from the new menu.

If that doesn't work, you may need to chat with the Ranorex support guys. Send an email to [email protected] and link to this thread in your email. They are more responsive through email most of the time.


Another option is to use user-code to scroll up/down until you find the row you are looking for and then click it.