Selecting an item in a ComboBox control

Ask general questions here.
jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Selecting an item in a ComboBox control

Post by jack_r_daniels » Fri Mar 12, 2010 4:55 pm

Hi all...

We are using Infragistics controls, and I'm trying to select an item from a ComboBox control using the item text.
According to the samples provided with Ranorex, we should be able to set the DropDownVisible attribute to true for the control, and then use the SelectedItemText attribute to select the item from the drop down list.

When I use that same code, it throws the below exception:
Ranorex.SetAttributeFailedException: Setting attribute 'dropdownvisible' failed on element '{ComboBox:Normal}'. ---> System.NotSupportedException: The operation is not supported.
at Ranorex.Plugin.MsaaFlavorElement.SetAttributeValue(Element element, String name, Object value)
at Ranorex.Core.Element.SetAttributeValue(String name, Object value)

Also, when I use the Spy to look at this control, it shows that there is a ComboBox control, and when you expand that there is another ComboBox control nested beneath it... not sure how this is developed form our end, but it could be that this ComboBox control is derived from the Infragistics control...

In any case, if you need more info please let me know. I've tried every way I can think of, and nothing has worked. Thank you.

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

Re: Selecting an item in a ComboBox control

Post by Ciege » Fri Mar 12, 2010 5:05 pm

Here is my ComboSelect framework method. Take a look, give it a try, modify it as needed. Let me know if this helps you at all. And I do not use the "DropDownVisible" attribute as it is not really needed if you check for other things such as the List that lives below the ComboBox.

Code: Select all

public static int ComboSelect(Ranorex.Form RanorexFormName, String ComboBoxName, string ComboBoxItem, bool boolHideNotFoundError)
{
    /************************************************************************
     * Function         : ComboSelect(Ranorex.Form RanorexFormName, String ComboBoxName, string ComboBoxItem)
     *
     * Description      : This function will search for and (if found)  
     *                  :  select an item within a ComboBox (drop list) on the form.
     *                         
     * Parameters       : RanorexFormName   - The form object the the ComboBox lives on
     *                  : ComboBoxName      - Name of the ComboBox to select
     *                  : ComboBoxItem      - Name of the item within the ComboBox to select
     *                  : boolHideNotFoundError - FALSE (default) - reports that the item was not found - returns -1
     *                  :                       - TRUE - Hides the error that the item was not found - Still returns -1
     *                  :                       - This option basically transforms this method into a check if exists method
     *                  
     * Return Type      : Integer
     * 
     * Return Value     : 0 for success, -1 for failure
     * 
     * Revision History
     * Date       : Author                    : Reason/Change
     * ---------- : ------------------------- : ------------------------------
     * 09/03/2009 : Chris Gendreau            : Initial Creation 
     * 12/10/2009 : Chris Gendreau            : Added HideNotFoundError option
    ************************************************************************/

    Ranorex.ComboBox HDComboBox;
    Ranorex.ListItem HDComboBoxListItem;
    Ranorex.Button HDComboListPageDown;
    Ranorex.Button HDComboListPageUp = null;
    Ranorex.ScrollBar HDComboListScrollBar;
    Ranorex.Button HDComboOpenButton = null;

    //Search for the ComboBox on the Form
    try
    {
        RanorexFormName.EnsureVisible();
        RanorexFormName.Activate();
        Thread.Sleep(500);
        HDComboBox = RanorexFormName.FindSingle(".//combobox[@controlname='" + ComboBoxName + "' or @text='" + ComboBoxName + "' or @controlid='" + ComboBoxName + "']", 60000);
        HDComboOpenButton = HDComboBox.FindSingle("button[@accessiblename='Open']", 30000);
    }

    catch (RanorexException e)
    {
        if (boolHideNotFoundError != true)
        {
            Report.Error("Unable to find ComboBox: " + ComboBoxName);
            Report.Error(e.ToString());
            Report.Screenshot();
        }
        return -1;
    }

    //Click the ComboBox
    try
    {
        if (HDComboBox.Enabled != true)
        {
            Report.Info("Combobox: " + ComboBoxName + " was not enabled so was not selectable");
            return -1;
        }

        Report.Debug("Clicking ComboBox: " + ComboBoxName);
        HDComboBox.Focus();
        Thread.Sleep(500);
        HDComboOpenButton.Click();
        Report.Debug("  Clicked ComboBox: " + ComboBoxName);
    }

    catch (RanorexException e)
    {
        Report.Error("Unable to click ComboBox: " + ComboBoxName);
        Report.Error(e.ToString());
        Report.Screenshot();
        return -1;
    }

    //Click the ComboBox list Item
    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;
    }

    return 0;
} //End ComboSelect
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...

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Fri Mar 12, 2010 10:43 pm

Hi ciege

Thanks for posting that function... I had already tried the approach you are using, and it didn't work for me... Clicking the Open button of the combobox works, but then clicking on the drop down list item fails... no error is thrown, but a random location on the screen seems to be clicked.
Very odd...

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

Re: Selecting an item in a ComboBox control

Post by Ciege » Fri Mar 12, 2010 10:53 pm

What version of Ranorex are you using?
In the past I had issues that would cause the mouse to move to 0,0 (top left) of the screen and click there. These issues were fixed with updating Ranorex to the most current at the time. I am still using version 2.1.4.6779 now.

After opening the combo box does RanorexSpy see the list object and the list items?

Also you can try the outputting the objects .valid and .screenlocation properties to the log to make sure they are correct.
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: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Selecting an item in a ComboBox control

Post by Ciege » Fri Mar 12, 2010 10:55 pm

One other thing. Maybe you can post a Ranorex Spy snapshot here for us to take a look at.
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...

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Mon Mar 15, 2010 3:46 pm

Hi Ciege

I'm on Ranorex version 2.2.2.7850 and as you said it is clicking on 0,0 (top left) of the window.
Perhaps the bug you are refering to is back. I wonder if you'd have some time to try this latest ranorex build against your app to see if ranorex will also try to click on 0,0

I'll also try to get the ScreenLocation properties to see what ranorex returns. Thanks.

Jack.

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Mon Mar 15, 2010 5:23 pm

Cieg / Support...

Below are the coordinates for the combobox, the open button and the list item... as you said, it is returning 0,0

I wonder if this is a bug, and what feedback Ranorex Support has... Thanks.

HDComboBox Screen Location: {X=539,Y=289}
HDComboBox location: {X=0,Y=0}
HDComboOpenButton Screen Location: {X=672,Y=291}
HDComboBox location: {X=133,Y=2}
HDComboBoxListItem Screen Location: {X=0,Y=0}
HDComboBoxListItem location: {X=0,Y=0}

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Mon Mar 15, 2010 8:47 pm

It would appear that the problem is limited to Infragistics controls... we have some regular windows combobox controls in our app and some that are infragistics. Those that are not infragistics comboboxes work just fine. Only infragistics controls fail.

Maybe I should be posting this on the Bug Reports forum?
Thanks.

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

Re: Selecting an item in a ComboBox control

Post by Ciege » Mon Mar 15, 2010 9:41 pm

I am in the process of upgrading to 2.2.2 to see what happens with my stuff. However, we use DevExpress controls so I may not be able to reproduce your issue.

Good luck...
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 an item in a ComboBox control

Post by Support Team » Tue Mar 16, 2010 5:35 pm

It looks like the MSAA implementation for that Infragistics control is broken. The individual tree items do not report a valid location to Ranorex, but always return an empty rectangle. That's why Ranorex always moves the mouse to the upper left corner of the desktop. Sadly, there is little we can do from our side right now, since the control is presenting wrong information to Ranorex.

However, as a workaround you can use the Accessible.DoDefaultAction on a list item in order to select it:
ListItem item = ...; // find the list item using RanoreXPath
Accessible accItem = new Accessible(item); // create Accessible adapter
accItem.DoDefaultAction();
Read the following section in the Ranorex User Guide to get more information on using Ranorex adapters: http://www.ranorex.com/support/user-gui ... apter.html

Regards,
Alex
Ranorex Support Team

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Tue Mar 16, 2010 11:08 pm

Thank you for your response Alex. That workaround did the trick... I'll be sure to use this approach from now on, and share it with the rest of the team.

Just wondering though; any reason why the call to set the dropdownvisible attribute fails, and throws the below exception? is that also a limitation of Infragistics? I am using the Open button click to open the list, so it's not really a problem, just thought I'd report it in case it was a bug.

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

Once again, thanks for the assist!

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 an item in a ComboBox control

Post by Support Team » Wed Mar 17, 2010 9:57 am

jack_r_daniels wrote:Just wondering though; any reason why the call to set the dropdownvisible attribute fails, and throws the below exception? is that also a limitation of Infragistics?
We use a common interface called MSAA (Microsoft Active Accessibility) to communicate with most Infragistics controls. Most of the Infragistics controls fully support this interface, but some - like that combobox - do not implement all functionality defined by the interface. That's why you see that "NotSupportedException" in the error message, that is thrown by the Infragistics control when Ranorex uses one of the MSAA interface methods.

Usually, if some functionality is not supported, there is a workaround to get by with. If not, we have good contacts to Infragistics and their commitment to collaborate to make their controls automatable with Ranorex.

Regards,
Alex
Ranorex Support Team

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Selecting an item in a ComboBox control

Post by jack_r_daniels » Wed Mar 17, 2010 3:06 pm

OK... Understood.
I have one more piece of feedback about automating Infragistics combobox controls...
When I use the Recorder to record clicking the open button of the infragistics combobox and then selecting an item in the list, the recorded actions are partially wrong. In other words, the recorded actions are:
1- a mouse click on the Open button (this is correct)
2- a mouse click on a ContainerScrolling_Region (xpath of element/table/container/container[@accessiblename='Scrolling Region'])

When I record the same actions on a non-infragistics combobox, it correctly records the second action as a click on the list item (xpath of listitem[@text='All'])

Hopefully you can pass this feedback to infragistics so that they can make this control accessible to automation. Thank you.