Page 1 of 1

use control id for buttons instead of class name?

Posted: Wed Nov 07, 2007 11:20 pm
by jasong
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?

problem retrieving control window handle by control ID

Posted: Thu Nov 08, 2007 12:21 am
by jasong
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?

Posted: Thu Nov 08, 2007 4:39 pm
by Support Team
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

similar problem with treeview child elements

Posted: Fri Nov 09, 2007 7:33 pm
by jasong
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

Posted: Fri Nov 09, 2007 7:43 pm
by Support Team
Does the function TreeViewSelectPath work?
Please also see the sample TreeViewTest.py.

Jenö
Ranorex Support Team