Ranorex

use control id for buttons instead of class name?

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexRecorder
View previous topic :: View next topic  
Author Message
jasong



Joined: 26 Oct 2007
Posts: 49
Location: Texas

PostPosted: Thu Nov 08, 2007 12:20 am    Post subject: use control id for buttons instead of class name?
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?
Back to top
View user's profile Send private message
jasong



Joined: 26 Oct 2007
Posts: 49
Location: Texas

PostPosted: Thu Nov 08, 2007 1:21 am    Post subject: problem retrieving control window handle by control ID
the Recorder used the following line of code to obtain an hWnd
Code: click into code to enlarge

control = Ranorex.ControlFindChildControlName(parent, 'radNo')


Because this control name is shared I tried using the Control ID obtained from RanorexSpy
Code: click into code to enlarge

control = Ranorex.ControlFindChildControlId(parent, 1509460)


This however, returned 0.

What is the correct way to do this?
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 256

PostPosted: Thu Nov 08, 2007 5:39 pm    Post subject:
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: click into code to enlarge
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! Smile

Alex
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
jasong



Joined: 26 Oct 2007
Posts: 49
Location: Texas

PostPosted: Fri Nov 09, 2007 8:33 pm    Post subject: 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
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 256

PostPosted: Fri Nov 09, 2007 8:43 pm    Post subject:
Does the function TreeViewSelectPath work?
Please also see the sample TreeViewTest.py.

Jenö
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexRecorder All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum