I'm trying to ge开发者_如何学Ct the listitems of a combobox using the following UI AUtomation code and zero items are being returned. There certainly are items in this comobbox so what am I doing wrong?
var comboBox = GetMarketAreasComboBox();
var items = comboBox.FindAll(TreeScope.Element, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
Where GetMarketAreasComboBox is defined as:
private AutomationElement GetMarketAreasComboBox()
{
var control = LocalRootAutomationElement.FindFirst(TreeScope.Descendants , new PropertyCondition(AutomationElement.AutomationIdProperty, "MarketAreasComboBox"));
Assert.IsNotNull(control);
return control;
}
It's possible that the list item elements have not yet loaded into memory. Expand the ComboBox, and then check for the ListItem elements
var comboBox = GetMarketAreasComboBox();
var comboBoxPattern = (ExpandCollapsePattern)comboBox.GetCurrentPattern(ExpandCollapsePattern.Pattern);
comboBoxPattern.Expand();
comboBoxPattern.Collapse();
var items = comboBox.FindAll(TreeScope.Element, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
A few things that I would have tried 1. Check if combo box is not null 2. Change scope to descendants for comboBox.FindAll. 3.Make sure I am hitting the code path when the list items are actually loaded under combo box (May be expand require as suggested by jvanbrakel above)
精彩评论