Page 1 of 1

Validate all items in a Combo Box

Posted: Wed Dec 16, 2009 10:24 pm
by costamesakid
I noticed a similar posting but unfortunately it did not contain the answer Im looking for.

I have a combo box (flavor msaa), that only returns the first item as its value rather then every item. Is there a way to validate every item in an msaa accessible combo box? Thanks

Re: Validate all items in a Combo Box

Posted: Wed Dec 16, 2009 10:42 pm
by Support Team
When the ComboBox is dropped down (and usually only then), there should be a List element under the ComboBox element containing all the values in the drop down list. Use the Instant Tracking mode (see http://www.ranorex.com/support/user-gui ... html#c1797) of Ranorex Spy to get the path to the list items.

Regards,
Alex
Ranorex Support Team

Re: Validate all items in a Combo Box

Posted: Wed Dec 16, 2009 11:04 pm
by Ciege
And just for giggles...
This is a snippet of code (error checking etc... removed) that will find a combobox, open it, then check for a given list item and click it.
You can expand on this to do the validate all items that you want.

Code: Select all

//Find Combo box
HDComboBox = RanorexFormName.FindSingle(".//combobox[@controlname='" + ComboBoxName + "' or @text='" + ComboBoxName + "']", 60000);

//Click Combo Box
HDComboBox.Click(Location.Center);

//Find a specific List Item
HDComboBoxListItem = HDComboBox.FindSingle<ListItem> ("list/listitem[@accessiblename='" + ComboBoxItem + "']");

//Click the Combo List Item
HDComboBoxListItem.Click();

Re: Validate all items in a Combo Box

Posted: Fri Dec 18, 2009 12:10 am
by costamesakid
Im not sure what Im doing wrong but there has be an easier way to get these items. Attached is a screen shot of the combo box I am trying to validate. And here is my code. It always fails on the 2nd method because Ranorex keeps comparing the text in the method to the text of the 1st item.

public static void Mouse_Click_ComboBoxUSMTF_20001()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Mouse Left Click item 'FormConfiguration_Wizard.ComboBoxUSMTF_2000' at 132;8.");
repo.FormConfiguration_Wizard.ComboBoxUSMTF_2000.Click("132;8");
}

public static void Validate_ListItemUSMTF_20001()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Validating AttributeEqual (Text='USMTF 2000') on item 'FormCfgwizard.ListItemUSMTF_2000'.");
Validate.Attribute(repo.FormCfgwizard.ListItemUSMTF_2000Info, "Text", "USMTF 2000");
}

public static void Validate_ListItemUSMTF_20041()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Validating AttributeEqual (Text='USMTF 2004') on item 'FormCfgwizard.ListItemUSMTF_2004'.");
Validate.Attribute(repo.FormCfgwizard.ListItemUSMTF_2004Info, "Text", "USMTF 2004");
}

public static void Validate_ListItemUSMTF_20061()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Validating AttributeEqual (Text='USMTF 2006') on item 'FormCfgwizard.ListItemUSMTF_2006'.");
Validate.Attribute(repo.FormCfgwizard.ListItemUSMTF_2006Info, "Text", "USMTF 2006");
}

public static void Validate_ListItemNot_using_ATO_ACOs1()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Validating AttributeEqual (Text='Not using ATO/ACOs') on item 'FormCfgwizard.ListItemNot_using_ATO_ACOs'.");
Validate.Attribute(repo.FormCfgwizard.ListItemNot_using_ATO_ACOsInfo, "Text", "Not using ATO/ACOs");
}
ScreenHunter_13 Dec. 17 16.39.gif

Re: Validate all items in a Combo Box

Posted: Fri Dec 18, 2009 12:37 am
by Ciege
This bit of code (for me) will find a combobox, click it, read the list of listitems within the combo box then messagebox them to the screen. If this bit works for you, you can then expand the foreach to do verifications -OR- just pass that MyListItems var to whatever method you want to puruse it...

Code: Select all

            Ranorex.ComboBox HDComboBox = RanorexFormName.FindSingle(".//combobox[@controlname='MyComboBoxName']", 60000);
            HDComboBox.Click(Location.Center);

            IList<Ranorex.ListItem> MyListItems = HDComboBox.FindDescendants<Ranorex.ListItem>();

            foreach (Ranorex.ListItem ThisListItem in MyListItems)
            {
                MessageBox.Show(ThisListItem.Text.ToString());
            }

Re: Validate all items in a Combo Box

Posted: Fri Dec 18, 2009 2:17 pm
by Support Team
costamesakid wrote:It always fails on the 2nd method because Ranorex keeps comparing the text in the method to the text of the 1st item.
You mean that the Validate_ListItemUSMTF_20041 method always throws a ValidationException, right?
Could you please post the repository containing the mentioned items or their paths!

Regards,
Alex
Ranorex Support Team