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?
use control id for buttons instead of class name?
problem retrieving control window handle by control ID
the Recorder used the following line of code to obtain an hWnd
Because this control name is shared I tried using the Control ID obtained from RanorexSpy
This however, returned 0.
What is the correct way to do this?
Code: Select all
control = Ranorex.ControlFindChildControlName(parent, 'radNo')
Code: Select all
control = Ranorex.ControlFindChildControlId(parent, 1509460)
What is the correct way to do this?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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.
That way you build the unique path to the required control.
Hope that helps!
Alex
Ranorex Support Team
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")
Hope that helps!

Alex
Ranorex Support Team
similar problem with treeview child elements
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
The child elements have the same name.
I tried the method you posted and it did not work.
Jason
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact: