Validate all items in a Combo Box

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

Validate all items in a Combo Box

Post by costamesakid » Wed Dec 16, 2009 10:24 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate all items in a Combo Box

Post by Support Team » Wed Dec 16, 2009 10:42 pm

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
.
Image

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

Re: Validate all items in a Combo Box

Post by Ciege » Wed Dec 16, 2009 11:04 pm

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();
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...

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

Re: Validate all items in a Combo Box

Post by costamesakid » Fri Dec 18, 2009 12:10 am

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

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

Re: Validate all items in a Combo Box

Post by Ciege » Fri Dec 18, 2009 12:37 am

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());
            }
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: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate all items in a Combo Box

Post by Support Team » Fri Dec 18, 2009 2:17 pm

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
.
Image