Page 1 of 1

How many ways to find GUI element i need?

Posted: Tue Jun 16, 2009 6:54 am
by marcushe
Environment: Ranorex2.1 ,Win7 RC US
My question:
A sample for Dxdiag.exe(directx11)
1. If no item is caught in project , I want to enumerate text lables on system tab ,what should i write?
I know Host.Local.Find can help , any others not by host?

2. One of your post is a sample ,to use Host.Local.Find to get element . Another post is a vistor here ,he use Element[] elementNames = controlElement.FindChildren(Role.Cell, elementName);
to get element.
Can you introduce all capacities to get UI element?

Re: How many ways to find GUI element i need?

Posted: Tue Jun 16, 2009 12:45 pm
by Support Team
For enumerating the labels in dxdiag.exe, you could use:
IList<Ranorex.Text> labels = Host.Local.Find<Ranorex.Text>("/form[@title='DirectX Diagnostic Tool']/container/text")
To your second question:

Host.Local is just an entry point which represents your local computer (the same as the "Host" in the Spy)

For searching you can use for example:

Form yourForm = "/form[@title='myform']";
This is the "shorthand" form for simple cases.

If you are looking for a single element then you use
Button button = yourParentElement.FindSingle<Button>("button[@controlid='4533'"]);
An exception is thrown if the method is not successful.

If you are looking for a collection of elements matching a given path you use:
IList<Button> allButtons = yourParentElement.Find<Button>("button");
Those "Find" methods also provide a number of overloads for specifying search timeouts, for example.

Michael
Ranorex Team

Re: How many ways to find GUI element i need?

Posted: Wed Jun 17, 2009 2:02 am
by marcushe
Michael ,Thanks great.
Haha ,i'm gload to get these . Maybe we can post our samples here to assist people improving their skill.