Selecting Hidden Items in Combo Box

Ask general questions here.
costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Selecting Hidden Items in Combo Box

Post by costamesakid » Wed Apr 07, 2010 5:14 pm

I saw a post on this same problem but the solution did not work for me. All I want to do is open a combo box and select an item. Seems simple enough, and the following code works fine if the item I want to select is visible when the combo box is opened:

Ranorex.ListItem listItem1 = ".//listitem[@accessiblename='" + Env + "']";
listItem1.Click("center");


But if the item I want to select is not visible (you have to scroll down to see it) then Ranorex will timeout. I tried the solution:

Ranorex.ComboBox Environmentcb = repo.FormSystem_Manager___UNCLASS.EvironmentCombo;
Environmentcb.Click("center");
Environmentcb.SelectedItemText=Env;


But when I execute this code Ranorex will just crash:

Ranorex.SetAttributeFailedException: Setting attribute 'selecteditemtext' failed on element '{ComboBox:NS}'. ---> System.NotSupportedException: The operation is not supported.
at Ranorex.Plugin.MsaaFlavorElement.SetAttributeValue(Element element, String name, Object value)

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Selecting Hidden Items in Combo Box

Post by Ciege » Wed Apr 07, 2010 5:33 pm

In this case what I do is check the Visible status of the list item. If it is not visible I find the Scrollbar object of the Combobox and scroll until the item becomes visible.

What this code does is
1) Check the visible status of the list item
2) If not visible find the Vertical scroll bar and the Page Up and Page down buttons of the scroll bar
3) Verify we are scrolled all the way to the top of the combo
4) While the list item is not visible, press the page down button on the scroll bar until it becomes visible
5) Click the list item

Code: Select all

            try
            {
                Report.Debug("Clicking ComboBox Item: " + ComboBoxItem);
                HDComboBoxListItem = HDComboBox.FindSingle<ListItem>("list/listitem[@accessiblename='" + ComboBoxItem + "' or @text='" + ComboBoxItem + "']");

                if (HDComboBoxListItem.Visible == false)
                {
                    HDComboListScrollBar = HDComboBox.FindSingle(".//scrollbar[@accessiblename='Vertical']", 60000);
                    if (HDComboListScrollBar.Value != 0)
                    {
                        HDComboListPageUp = HDComboBox.FindSingle(".//scrollbar/button[@accessiblename='Page up']", 60000);
                    }
                    while (HDComboListScrollBar.Value != 0)
                    {
                        HDComboListPageUp.Click();
                    }

                    HDComboListPageDown = HDComboBox.FindSingle(".//scrollbar/button[@accessiblename='Page down']", 60000);
                    while (HDComboBoxListItem.Visible == false)
                    {
                        HDComboListPageDown.Click();
                    }
                }
                
                HDComboBoxListItem.Click();
                Report.Debug("  Clicked ComboBox Item: " + ComboBoxItem);
            }

            catch (RanorexException e)
            {
                Report.Error("Unable to click ComboBox Item: " + ComboBoxItem);
                Report.Error(e.ToString());
                Report.Screenshot();
                return -1;
            }
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Selecting Hidden Items in Combo Box

Post by Support Team » Wed Apr 07, 2010 10:59 pm

costamesakid wrote:But if the item I want to select is not visible (you have to scroll down to see it) then Ranorex will timeout.
Apparently, Ranorex can only detect visible items in your Combobox control. You can easily check that by analyzing the Combobox using Ranorex Spy (use Instant Tracking to analyze the Combobox drop-down-list). Whether Ranorex can list invisible items or not, depends on the implementation of the Combobox control (in particular, its MSAA interface implementation).

Regards,
Alex
Ranorex Support Team

costamesakid
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Re: Selecting Hidden Items in Combo Box

Post by costamesakid » Thu Apr 08, 2010 8:19 am

What exactly am I looking for when I Instant Spy a list item in the combo box? As in, what should be in the Path indicating that the 'hidden' items can be recognized by Ranorex?

We alleviated this issue internally by having our Dev Team make the combo boxes in our Qt application editable, meaning we could type the full value into the combo box instead of selecting it. But I still would like to know what else we can do in the future to select a 'hidden' list item instead of having to type the value. Thanks!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Selecting Hidden Items in Combo Box

Post by Support Team » Thu Apr 08, 2010 8:26 am

Just look at the element tree and compare the list items displayed in Ranorex Spy with the ones in your application. If Ranorex Spy only shows the currently visible list items, then obviously your Combobox control's MSAA implementation only provides visible items, no invisible ones.

Regards,
Alex
Ranorex Support Team

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Selecting Hidden Items in Combo Box

Post by Ciege » Thu Apr 08, 2010 4:08 pm

The Combo list items may be "lazy loaded". In other words they do not exist until they are visible. I have not personally seen that on a list box but have seen that in different trees and grids.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...