How to find form descendants by name OR instance

Ask general questions here.
User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

How to find form descendants by name OR instance

Post by Ciege » Thu Feb 26, 2009 8:24 pm

I am using VS2008, C# with Ranorex.

Currently I can find items on my form by name by using the command

Code: Select all

HDradiobutton = RanorexFormName.FindDescendant<Ranorex.RadioButton>(RadioButtonName);
However, I have run into two radio buttons on the same form that have no AccessibleName (bad I know, but thats what I got). How do I use the FindDescendant command to find an item by instance number 0 & 1?

Thanks!

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

Post by Support Team » Fri Feb 27, 2009 11:01 am

AccessibleName is only available in MSAA based controls.

You can use the FindDescendants method to retrieve a list of RadioButtons and distinguish per index.

or

you use Form.Find() and indexing over the pos(num) method in the rxPath e.g.

Code: Select all

formCalculator.Find<Ranorex.RadioButton>("radiobutton[@text='Bin' and pos()='1']");
Regards,
Christian
Ranorex Support Team

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

Post by Ciege » Fri Feb 27, 2009 10:05 pm

OK, I've tried (and failed with) the following to find an object with the following rXpath:

Code: Select all

/form[@title='Setup' and @processname='is-NK3G2.tmp' and @class='TWizardForm']/element[@processname='is-NK3G2.tmp' and @class='TNewNotebook']/element[@processname='is-NK3G2.tmp' and @class='TNewNotebookPage' and @instance='0']/element[@processname='is-NK3G2.tmp' and @class='TNewNotebook']/element[@processname='is-NK3G2.tmp' and @class='TNewNotebookPage' and @instance='0']/element[@processname='is-NK3G2.tmp' and @class='TRadioButton' and @instance='1']/radiobutton

Code: Select all

Ranorex.Form RanorexFormName = Host.Local.FindChild<Ranorex.Form>("Setup");
Ranorex.RadioButton HDObject1;
HDObject1 = RanorexFormName.FindSingle<Ranorex.RadioButton>("*/element[@class='TRadioButton' and @instance='1']/radiobutton");
-OR-

Code: Select all

Ranorex.Form RanorexFormName = Host.Local.FindChild<Ranorex.Form>("Setup");
Ranorex.RadioButton HDObject1;
HDObject1 = RanorexFormName.FindDescendant<Ranorex.RadioButton>("*/element[@class='TRadioButton' and @instance='1']/radiobutton");

Each one fails with a Ranorex.ElementNotFoundException


EDIT: not sure where the space is coming from in the code preview snippet 1 for TRadioButton and code preview snippet 2 after @class= but in what I have typed here and in my code there is no extra space.

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

Post by Support Team » Mon Mar 02, 2009 2:23 pm

The problem is that you made an error when simplifying your RxPath: "*" in an RxPath stands for "any capability" (e.g. "form", "element", or "button") and not for "descendant". If you want all descendants to be searched, you need to use ".//". Consequently, you need to replace the "*" in you path with ".//". Please refer to the RanoreXPath documentation for more info:
http://www.ranorex.com/support/user-gui ... html#c1792

In addtion, please note that only the Find and FindSingle adapter methods take RxPaths as parameter, whereas the FindChild and FindDescendant adapter methods search for the defaultlabel of elements.

Regards,
Alex
Ranorex Support Team