use control id for buttons instead of class name?

Ranorex Spy, Recorder, and Studio.
jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

use control id for buttons instead of class name?

Post by jasong » Wed Nov 07, 2007 11:20 pm

I just came across a winforms form (.NET) where a two different sets of radio buttons had the 'No' both with the same class name. When selecting both to 'No' and then playing back, only one was set to 'No'. (the first one)

Would it be better to use the controlID since it is unique?

jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

problem retrieving control window handle by control ID

Post by jasong » Thu Nov 08, 2007 12:21 am

the Recorder used the following line of code to obtain an hWnd

Code: Select all

control = Ranorex.ControlFindChildControlName(parent, 'radNo')
Because this control name is shared I tried using the Control ID obtained from RanorexSpy

Code: Select all

control = Ranorex.ControlFindChildControlId(parent, 1509460)
This however, returned 0.

What is the correct way to do this?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Nov 08, 2007 4:39 pm

You should not use the ControlId with .NET controls since it is always equal to the corresponding window handle. Therefore, the control ID is unique, but may change frequently (e.g. after a restart of the application).

Usually the recorder searches .NET controls by their control name. So, as long as all the control names differ, you should not run into a problem.

To prevent problems caused by identical control names, the recorder also stores the parent control of controls. From your problem description I suppose that the parent controls of the radio buttons have the same control name. That's why the recorder always finds the first parent control and therefore the same radio button.

So, what you can do is: try searching for the parent's parent first. I.e. if the radio button is in a group box that is itself in a panel, search the panel first by its control name. Then search the panel for the group box and finally the group box for the radio button.

Code: Select all

parent = Ranorex.FormFindChildControlName(form, "panel1")
parent = Ranorex.ControlFindChildControlName(parent, "groupBox1")
control = Ranorex.ControlFindChildControlName(parent, "radNo")
That way you build the unique path to the required control.

Hope that helps! :)

Alex
Ranorex Support Team

jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

similar problem with treeview child elements

Post by jasong » Fri Nov 09, 2007 7:33 pm

This may be a separate issue, but when trying to select child elements from treeview elements I have problems.
The child elements have the same name.

I tried the method you posted and it did not work.

Jason

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Fri Nov 09, 2007 7:43 pm

Does the function TreeViewSelectPath work?
Please also see the sample TreeViewTest.py.

Jenö
Ranorex Support Team