How to get combo box items from the parent element

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from

Therefore, the best option is to get Coded UI controls from the parent control and to get from it all the children items using  the Add a new control to the UIMap tool (see

In the next example a combo box is presented with a list of countries.  The strategy to follow is to get only the red squared UI Control and from it get both all the countries items of the list.


A method to click in any list item of a combo box (for example Germany) from the parent element is shown in the next class. The key point is to use first Items.ToList():

public static WinComboBox ComboBox;

public static List GetElementsFromComboBox;

private static Dictionary objDict = UiTestComboBoxDict.UiTestComboBox();

public static void MouseClickInComboBoxElement(string nameComboBoxElement, string dictKey)
	ComboBox = objDict[dictKey];
	UITestControl elemeUiTestControl =
		ComboBox.Items.ToList().FirstOrDefault(element => element.Name == nameComboBoxElement);

	if (elemeUiTestControl != null)
		Assert.Fail("The next combobox element does  not exist: " + nameComboBoxElement);

As it is shown in the previous code the UI Control of the combo box parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s