Table with combo boxes

Class library usage, coding and language questions.
mollusk
Posts: 5
Joined: Wed Dec 13, 2006 9:08 pm

Table with combo boxes

Post by mollusk » Thu Mar 22, 2007 5:38 am

Hi.
I'm trying to access combo boxes in a table. What I need to do is:

1. get the number of items in each combo box
2. list the items in each combo box
3. select each item in each combo box

I'm having trouble with this. All the Ranorex combobox functions require the handle to the combobox in question, but I can't figure out how to get that.

So far what I have is something like this which returns the combobox tuple:

Code: Select all

import RanorexPython as r
...
table = r.ElementFindChild(formElement, r.ROLE_SYSTEM_TABLE)
row = r.ElementGetChild(table, 1) # get the first row after the table header

# This returns a tuple not a handle!
combo = r.ElementFindChild(row, r.ROLE_SYSTEM_COMBOBOX)
Any help much appreciated :-)

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

Post by admin » Thu Mar 22, 2007 8:20 pm

The first element of the tuple is the handle of the control.
Print out the tuple and check the handle with RanorexSpy.

Jenö
Ranorex Team

mollusk
Posts: 5
Joined: Wed Dec 13, 2006 9:08 pm

Post by mollusk » Fri Mar 23, 2007 12:27 am

That's what I assumed it would be, but on inspection the handle is the formElement's. If I spy on the combo itself when it is selected it has a completely different handle.
Using the following code I always get the number zero no matter how many items are in the combo.

Code: Select all

print r.ComboBoxGetItemCount(combo[0])

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

Post by admin » Sat Mar 24, 2007 8:25 pm

The following code works with the Ranorex sample application VS2005Application.exe.
It searches the list element of the combo box and reads all list items, it should also work with your combo box.

Code: Select all

print '--------------------------------------------------------------------'
print ' Searching the combobox'
print '---------------------------------------------------------------------'
print '   searching the comboBox by control name'
comboBox=Ranorex.FormFindChildControlName(form,'comboBox1')
if comboBox == 0:
    print 'ERROR: comboBox not found'
    return 1        

print '      moving the mouse to the control'

element=Ranorex.ControlGetElement(comboBox)
combo = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_COMBOBOX)
if combo == None:
    print 'ERROR: combobox element not found'
    return 1        

Ranorex.MouseClickElement(combo)

comboList = Ranorex.ElementFindChild(combo, Ranorex.ROLE_SYSTEM_LIST)
if comboList == None:
    print 'ERROR: list of the combobox element not found'
    return 1        

itemCount = Ranorex.ElementGetChildCount(comboList);
for index in range(0,itemCount):
    item = Ranorex.ElementGetChild(comboList,index)
    if item == None:
        break
    print '      Item = ' + Ranorex.ElementGetName(item)
Please see also the function DumpElementTree from the sample ElementTest.py

Jenö
Ranorex Team