XPath shortcuts?

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

XPath shortcuts?

Post by Aracknid » Fri Jun 10, 2011 7:58 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: XPath shortcuts?

Post by Ciege » Fri Jun 10, 2011 9:08 pm

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);
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...

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: XPath shortcuts?

Post by Aracknid » Fri Jun 10, 2011 9:27 pm

Ah, I see. The light just went on.

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

Thanks,

Aracknid.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: XPath shortcuts?

Post by Ciege » Fri Jun 10, 2011 9:31 pm

Always nice when the light comes on! :idea:

Unfortunately, it almost never stays on for any length of time! :roll:
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...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: XPath shortcuts?

Post by Support Team » Sat Jun 11, 2011 1:10 pm

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

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: XPath shortcuts?

Post by Aracknid » Mon Jun 13, 2011 2:44 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: XPath shortcuts?

Post by Support Team » Tue Jun 14, 2011 1:07 pm

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