how do I select ComboBox\'s SelectedIndex = -1?
I wrote a code to automate testing:
AutomationElement aeBuildMachine = null;
int count =
public static void SetComboBox(AutomationElement ComboxBox, string SelectedValue)
{
AutomationElement ListBox = ComboxBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "ListBox"));
AutomationElement SelectedItem = ListBox.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, SelectedValue));
((SelectionItemPattern)SelectedItem.GetCurrentPattern(SelectionItemPattern.Pattern)).Select();
}
Instruction on how to use: 1) Copy and Paste into Utility Class 2) Find your ComboBox AutomationElement 3) Utility.SetCombox(ComboxAutomationElement, "SelectedText")
To understand:
Tree structure of ComboBox as follow:
ComboBox->ListBox (children)->ListItems(children) [each combobox has a ListBox as a child, and the ListBox has all ListItems as children].
Each ListItem has SelectedItemPattern, invoke which you want to select.
I later found out that "Shaz " has better coding, and i vote him as the best code.
** Comment: To do UIAAutomation, you must map the AutomationElements of your application to a TreeView, which makes everything simple and understood.