2011-06-23 32 views
1

我想要使用下面的UI獲取組合框的listitems AUtomation代碼並返回零項。這個comobbox當然有物品,所以我做錯了什麼?Microsoft UI自動化不返回預期的組合框項目

var comboBox = GetMarketAreasComboBox(); 
var items = comboBox.FindAll(TreeScope.Element, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); 

凡爲GetMarketAreasComboBox定義:

private AutomationElement GetMarketAreasComboBox() 
{ 
    var control = LocalRootAutomationElement.FindFirst(TreeScope.Descendants , new PropertyCondition(AutomationElement.AutomationIdProperty, "MarketAreasComboBox")); 
    Assert.IsNotNull(control); 
    return control; 
} 

回答

2

這有可能是列表項元素還沒有加載到內存中。展開組合框,然後檢查的列表項元素

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)); 
1

,我會盡量 1.檢查有幾件事情,如果組合框不爲空 2.更改範圍子孫comboBox.FindAll。 3.當組合框實際加載列表項時,請確保我點擊代碼路徑(可能會按照上面的jvanbrakel的建議擴展require)