how do I select ComboBox\'s SelectedIndex = -1?
I wrote a code to automate testing:
AutomationElement aeBuildMachine = null;
int count =
I thought I would share this as a simple way to select any item from a ComboBox or other item container:
protected AutomationElement GetItem(AutomationElement element, string item)
{
AutomationElement elementList;
CacheRequest cacheRequest = new CacheRequest();
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children;
elementList = element.GetUpdatedCache(cacheRequest);
foreach (AutomationElement child in elementList.CachedChildren)
if (child.Cached.Name == item)
return child;
return null;
}
element is the ComboBox or item container, item is the string name or literal value of the item in the container. Once you have the item you can do the following to select it:
protected void Select(AutomationElement element)
{
SelectionItemPattern select = (SelectionItemPattern)element.GetCurrentPattern(SelectionItemPattern.Pattern);
select.Select();
}
Hope this helps others. I derived this pattern from the MSDN documentation on Automation, found here:
MSDN - Automation and Cached Children