Page 1 of 1

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

Posted: Tue Dec 04, 2007 6:23 pm
by jasong
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?

Posted: Tue Dec 04, 2007 6:28 pm
by jasong
I am also having the same problem with selecting tabs.

Is there a way to avoid using the location?

Posted: Tue Dec 04, 2007 10:56 pm
by Support Team
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

Posted: Wed Dec 05, 2007 5:00 pm
by jasong
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

Posted: Wed Dec 05, 2007 6:02 pm
by Support Team
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