how can I pick an element from a form without display

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

how can I pick an element from a form without display

Post by jasong » Fri Dec 07, 2007 5:35 pm

Given you have a combo box with 50 items, is it possible to select one of those items without scrolling down to it?

My problem is that in order to make this script reusable, I am entering the value in as a variable. That means I can not know the number of clicks for scrolling (or move the scroll bar) merely I just need to select the entry.

I have tried using ComboBoxFindString, ElementFindChild, and ComboBoxSetSelectedText and they have not worked.

---- edited
I realized this also is a need for all forms. In our main window we have many controls and fields and take up multiple 'pages'.

Can I pick the control without scrolling the page down to it? I notice that TreeViewSelectItem mentions scrolling an item into view and selecting it. Is there another equivalent method for forms in general (and controls like a combobox)?

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 » Fri Dec 07, 2007 6:00 pm

Is the text field of the combo box editable?

Jenö
Ranorex Team

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

Post by jasong » Mon Dec 10, 2007 4:49 pm

Some are. I have switched to using ControlSendKeys on those.

Others are but there are issues as to how you can select via key entry.

For example, one combobox is for US states. You can not enter 'CO' in that field as it will first select 'CA' (with the 'C' entry) and then switch to 'OH' with the 'O' entry.
You are forced to cycle through the list by number of repetative key entries. For example here, to select 'CO' you must enter 'C' twice.

This requires foreknowledge of the contents of the list which goes against reuse.

Is there a way to just select the combobox field then pick the entry from the list of available values?

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 11, 2007 12:09 am

You can also set the items of a combo box as follows:

Code: Select all

element = Ranorex.ControlGetElement(comboBox)

# Use this line if the textbox of the combo is editable 
#text = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_TEXT)

# Use this line if the textbox of the combo is not editable (static) 
text = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_STATICTEXT)

Ranorex.ElementSetValue(text, 'Text')

itemCount = Ranorex.ElementFindChildren(element, Ranorex.ROLE_SYSTEM_LISTITEM) 
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]
    Ranorex.ElementSetValue(text, child[2])
If you want to select only one item, use the following:

Code: Select all

element = Ranorex.ControlGetElement(comboBox)

# Use this line if the textbox of the combo is editable 
#text = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_TEXT)

# Use this line if the textbox of the combo is not editable (static) 
text = Ranorex.ElementFindChild(element, Ranorex.ROLE_SYSTEM_STATICTEXT)

Ranorex.ElementSetValue(text, 'Text')
Hope it works for you.

Jenö
Ranorex Team