开发者

Microsoft UI Automation not returning expected ComboBox items

开发者 https://www.devze.com 2023-03-15 08:53 出处:网络
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 wro

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消