How many ways to find GUI element i need?

Ask general questions here.
marcushe
Posts: 112
Joined: Tue Apr 14, 2009 6:38 am

How many ways to find GUI element i need?

Post by marcushe » Tue Jun 16, 2009 6:54 am

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?

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

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

Post by Support Team » Tue Jun 16, 2009 12:45 pm

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

marcushe
Posts: 112
Joined: Tue Apr 14, 2009 6:38 am

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

Post by marcushe » Wed Jun 17, 2009 2:02 am

Michael ,Thanks great.
Haha ,i'm gload to get these . Maybe we can post our samples here to assist people improving their skill.