with ComboBox, how to open up list or just select an item

Class library usage, coding and language questions.
jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

with ComboBox, how to open up list or just select an item

Post by jasong » Tue Dec 04, 2007 6:23 pm

Two related questions:
Given a combo box, how do you select an item from the dropdown list without expanding the list?

To avoid location changes, how can you open up the list of items?

Here is what the recorder generated:

Code: Select all

control = Ranorex.ControlFindChildControlName(parent, "cboCtsClient")
    if control == 0:
        return 1
    Ranorex.ControlSetFocus(control);
    controlElement = Ranorex.ControlGetElement(control)
    if controlElement == None:
        return 1

    element = Ranorex.ElementFindChildLocation(controlElement, 43, "Open", "", 296, 320)
    if element == None:
        return 1
However, the use of a location is very dangerous for reuse.

I tried the following in place of ElementFindChildLocation but it returned None.

Code: Select all

element = Ranorex.ElementFindChild(controlElement, 43, "Open", "WindowsForms10.COMBOBOX.app2", Ranorex.MATCH_SUBSTRING)
Am I using the right approach?

jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

Post by jasong » Tue Dec 04, 2007 6:28 pm

I am also having the same problem with selecting tabs.

Is there a way to avoid using the location?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Tue Dec 04, 2007 10:56 pm

Is there a way to avoid using the location?
Yes, you can also use the ElementFindChild function with the same arguments but without positions.

Use the:

Code: Select all

element = Ranorex.ElementFindChild(controlElement, 43, "Open", "");
instead of:

Code: Select all

element = Ranorex.ElementFindChildLocation(controlElement, 43, "Open", "", 296, 320);
But if you have two controls with the same Role, Name and ClassName, then you will get the first one without positions.

Jenö
Ranorex Team

jasong
Posts: 49
Joined: Fri Oct 26, 2007 9:38 pm
Location: Texas

Post by jasong » Wed Dec 05, 2007 5:00 pm

Thank you, this is working great.

One thing I noticed with another tool was that it enumerated duplicates like you mentioned using an underscore.

so it would be control, control_2, control_3

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Wed Dec 05, 2007 6:02 pm

You can enumerate all elements with the same Role as follows:

Code: Select all

itemCount = Ranorex.ElementFindChildren(element, Ranorex.ROLE_SYSTEM_CHECKBUTTON)

for index in range(0,itemCount):
    child= Ranorex.ElementGetChildFieldItem(index)
    if child == None:
        print 'Cannot read child' + str(index)
        continue;
    print 'child item =' + child[2]
If you only want to read the third child, you can do the following:

Code: Select all

itemCount = Ranorex.ElementFindChildren(element, Ranorex.ROLE_SYSTEM_CHECKBUTTON)
child= Ranorex.ElementGetChildFieldItem(2)  # third child
You can also read all elements with a specified Role and Name as follows:

Code: Select all

itemCount = Ranorex.ElementFindChildren(element, Ranorex.ROLE_SYSTEM_CHECKBUTTON, 'ndNode', "", Ranorex.MATCH_SUBSTRING)
for index in range(0,itemCount):
    child= Ranorex.ElementGetChildFieldItem(index)
    if child == None:
        print 'Cannot read child' + str(index)
        continue;
    print 'child item =' + child[2]
Jenö
Ranorex Team