Selecting Hidden Items in Combo Box : General Questions

Selecting Hidden Items in Combo Box

Ask general questions here.

Selecting Hidden Items in Combo Box

Postby costamesakid » Wed Apr 07, 2010 6: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)
costamesakid
 
Posts: 81
Joined: Tue Jun 16, 2009 11:27 pm

Re: Selecting Hidden Items in Combo Box

Postby Ciege » Wed Apr 07, 2010 6: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
Ciege
 
Posts: 907
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: Selecting Hidden Items in Combo Box

Postby Support Team » Wed Apr 07, 2010 11: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
User avatar
Support Team
Site Admin
 
Posts: 4289
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Selecting Hidden Items in Combo Box

Postby costamesakid » Thu Apr 08, 2010 9: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!
costamesakid
 
Posts: 81
Joined: Tue Jun 16, 2009 11:27 pm

Re: Selecting Hidden Items in Combo Box

Postby Support Team » Thu Apr 08, 2010 9: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
Support Team
Site Admin
 
Posts: 4289
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Selecting Hidden Items in Combo Box

Postby Ciege » Thu Apr 08, 2010 5: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...
User avatar
Ciege
 
Posts: 907
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests