Ranorex

How can I find child objects if they have no name?

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



Joined: 20 Sep 2006
Posts: 2
Location: London

PostPosted: Wed Sep 20, 2006 4:00 pm    Post subject: How can I find child objects if they have no name?
Hi,

I'm automating a web application that has a number of comboboxes inside a frame. The comboboxes don't have individual names but I can identify them by their control ids or instances of class name (ThunderRT6ComboBox). I want to be able to grab all of the objects within the frame, go through each object in a loop and see if it's a combobox, and if it is, see if it contains the selection that I want to make. Can I do this and if so how? I've been looking at elements and all the samples but these are based on knowing the name of the object (which I don't have).

Thanks for any help you can give.

Mik
Back to top
View user's profile Send private message Send e-mail
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Sep 21, 2006 11:15 pm    Post subject:
The following sample searches an explorer control in an application, goes through the combo boxes, prints out the actual value of each combo box, and selects the text 'mytext' if the combo box has an item with this name.

Code: click into code to enlarge
    control = Ranorex.FormFindChildClassName(form, "Internet Explorer_Server");
    if control == None:
        print 'ERROR: Cannot find explorer';
        return -3;

    element = Ranorex.ControlGetElement(control);
    if element != None:
        DumpElementTree(element, 0);


The function DumpElementTree prints out each combo box in the control.

Code: click into code to enlarge
def DumpElementTree(element,level):
    level = level+1;
    childCount = Ranorex.ElementGetChildCount(element);
    for index in range(0,childCount):
        child= Ranorex.ElementGetChild(element,index)
        if child == None:
            continue;

        role = Ranorex.ElementGetRole(child);
        if role == Ranorex.ROLE_SYSTEM_COMBOBOX:
            print '----------------------'
            print '   Name=',
            print Ranorex.ElementGetName(child)
            print '   Value=',
            print Ranorex.ElementGetValue(child)
            print '   Position=',
            print str(Ranorex.ElementGetPosition(child))
            Ranorex.MouseMoveToElement(child)
            item = Ranorex.ElementFindChild(child, Ranorex.ROLE_SYSTEM_LISTITEM, 'myself');
            if item != None:
                Ranorex.ElementSelect(item,Ranorex.SELFLAG_TAKESELECTION);

        DumpElementTree(child,level);


This sample works with the actual Ranorex version, you can do a little bit more in the next version (V0.9.4).
Please contact me if you cannot solve your problem with this version, i can send you a V0.9.4Beta1.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
Milton70



Joined: 20 Sep 2006
Posts: 2
Location: London

PostPosted: Fri Sep 22, 2006 9:02 am    Post subject:
Thanks for the info, I'll try it out and see what happens Surprised

Regards

Milton
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexPython 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