Page 1 of 1

XPath shortcuts?

Posted: Fri Jun 10, 2011 7:58 pm
by Aracknid
I'm wondering if there are shortcuts that I can take to finding objects in my app with Xpaths. So what I mean is this:

In a different testing tool, if I wanted to find a textbox that had a unique ID, I could simply say something like:

Code: Select all

MyTextbox = TextBox("ID='MyUniqueID'")
In Ranorex, I'm providing an Xpath which is sometimes very long...

Code: Select all

MyText = "/form/blah/blah/blah/....../blah/text[@automationID='MyUniqueID'" 
(only picture this being longer) :)

Is it possible in Ranorex to simply say something shorter, like

Code: Select all

MyText = "text[@automationID='MyUniqueID'"

And it will find it no matter where it is in the app?

Thanks,

Aracknid

Re: XPath shortcuts?

Posted: Fri Jun 10, 2011 9:08 pm
by Ciege
You can, but keep in mind the more levels deep Ranorex has to search for something the longer it may/will take. But you can root your search from the desktop and get all Apps or root your search from the main form (or any sub form) of your AUT and you can find the object you are looking for. I do it this way with my automation framework. I can pass in the root form I want to search from and the object name I want to search for.

For example, I have a method called PushButtonClick that takes 2 parameters. 1: root form and 2: name of the pushbutton. The method searches for that pushbutton and then clicks it if found or returns a failure result. Obviously you can add various methods that finds and interact with all types of objects.

Method header
public static int PushButtonClick(Ranorex.Form RanorexFormName, String PushButtonName)
Code from within the method that does the find
HDbutton = RanorexFormName.FindSingle(".//button[@controlname='" + PushButtonName + "' or @text='" + PushButtonName + "']", 60000);

Re: XPath shortcuts?

Posted: Fri Jun 10, 2011 9:27 pm
by Aracknid
Ah, I see. The light just went on.

Learning a new automation tool is both fun and frustrating. :D

Thanks,

Aracknid.

Re: XPath shortcuts?

Posted: Fri Jun 10, 2011 9:31 pm
by Ciege
Always nice when the light comes on! :idea:

Unfortunately, it almost never stays on for any length of time! :roll:

Re: XPath shortcuts?

Posted: Sat Jun 11, 2011 1:10 pm
by Support Team
Aracknid wrote:Is it possible in Ranorex to simply say something shorter, like
MyText = "text[@automationID='MyUniqueID'"
And it will find it no matter where it is in the app?
Have a look at the Ranorex User Guide section on RanoreXPath:
http://www.ranorex.com/support/user-gui ... html#c3296
It explains all the operators you can use in RanoreXPaths, like the "//" operator that searches all descendants of the current element.

Regards,
Alex
Ranorex

Re: XPath shortcuts?

Posted: Mon Jun 13, 2011 2:44 pm
by Aracknid
Yes, thanks. I've read that RXPath post a few times before (and it is really useful), but I guess I was not really looking for that as I read it. It's a small subtle difference that is easy to overlook.

Since we are on the subject, in the Axes section of the RXpath post, when reffering to "the current element", what are the ways to use this so that it knows what the current element is? Above, Ciege provided some sample code where he used a "FindSingle". Is that the intended way to use the Axes with the "." in the front, or are there other ways as well?

Aracknid.

Re: XPath shortcuts?

Posted: Tue Jun 14, 2011 1:07 pm
by Support Team
Hi,
What are the ways to use this so that it knows what the current element is?
If you are working with Ranorex Spy you can use "Set Element as Root" to set the current element. Now you can enter a relative path into the text box at the top of the Spy with the element you've just set as root set as current element.
If you are working in Ranorex Studio with code you can use following methods to get controls relative to the control you are searching from: Regards,
Tobias
Support Team