How to identify object based on their name and not position

Ask general questions here.
mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

How to identify object based on their name and not position

Post by mghali » Wed Aug 06, 2014 2:56 pm

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?

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

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

Post by krstcs » Wed Aug 06, 2014 3:30 pm

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?
Shortcuts usually aren't...

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

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

Post by mghali » Wed Aug 06, 2014 4:59 pm

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']
Last edited by mghali on Wed Aug 06, 2014 5:22 pm, edited 1 time in total.

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

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

Post by krstcs » Wed Aug 06, 2014 5:18 pm

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
Shortcuts usually aren't...

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

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

Post by mghali » Wed Aug 06, 2014 5:40 pm

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

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

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

Post by krstcs » Wed Aug 06, 2014 6:41 pm

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.
Shortcuts usually aren't...

mghali
Posts: 26
Joined: Fri Jul 18, 2014 9:05 pm

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

Post by mghali » Wed Aug 06, 2014 7:23 pm

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

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

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

Post by krstcs » Wed Aug 06, 2014 8:28 pm

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.
Shortcuts usually aren't...