how do I select ComboBox\'s SelectedIndex = -1?
I wrote a code to automate testing:
AutomationElement aeBuildMachine = null;
int count =
For me, the answer by gotmug required the CacheRequest to be activated. I implemented this as an extension method
public static bool SelectDropDownItem(this AutomationElement comboBoxElement, string item)
{
bool itemFound = false;
AutomationElement elementList;
CacheRequest cacheRequest = new CacheRequest();
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children;
using (cacheRequest.Activate())
{
// Load the list element and cache the specified properties for its descendants.
Condition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List);
elementList = comboBoxElement.FindFirst(TreeScope.Children, cond);
}
//Loop thru and find the actual ListItem
foreach (AutomationElement child in elementList.CachedChildren)
if (child.Cached.Name == item)
{
SelectionItemPattern select = (SelectionItemPattern)child.GetCurrentPattern(SelectionItemPattern.Pattern);
select.Select();
itemFound = true;
break;
}
return itemFound;
}