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

Class library usage, coding and language questions.
Posts: 2
Joined: Wed Sep 20, 2006 2:25 pm
Location: London

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

Post by Milton70 » Wed Sep 20, 2006 3:00 pm


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.


Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Thu Sep 21, 2006 10:15 pm

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: Select all

    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: Select all

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:

        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))
            item = Ranorex.ElementFindChild(child, Ranorex.ROLE_SYSTEM_LISTITEM, 'myself');
            if item != None:


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

Posts: 2
Joined: Wed Sep 20, 2006 2:25 pm
Location: London

Post by Milton70 » Fri Sep 22, 2006 8:02 am

Thanks for the info, I'll try it out and see what happens :o