繁体   English   中英

Windows UI自动化选择组合框的项目

[英]Windows UI Automation select item of combobox

我正在尝试使用Windows UI自动化API根据其值选择一个项目。

我有一个类ComboBox ,它继承自UIAutomation.Element

此外,我在此combobox元素上有一个方法,应该可以使用string来调用该方法以选择匹配的combobox-item

我尝试了以下方法:

public void SetSelectedItem(string itemName, ITimeout timeout = null)
{
    var comboboxItem = this.GetSelf(timeout).FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

    var expandCollapsePattern = (ExpandCollapsePattern)this.GetSelf(timeout).GetCurrentPattern(ExpandCollapsePattern.Pattern);
    expandCollapsePattern.Expand();
    var itemToSelect = ?????

    var selectItemPattern = (SelectionItemPattern)itemToSelect.GetCurrentPattern(SelectionItemPattern.Pattern);
    selectItemPattern.Select();
}

但是我真的不知道如何在var itemToSelect = ?????行检索正确的项目。

变量comboboxItem的类型为AutomationElementCollection但不幸的是,Linq似乎无法使用此类型...

您知道如何检索正确的物品吗?

还是我做错了其他事?

提前致谢

由于@TnTinMn的提示,我找到了答案,谢谢! :-)

public void SetSelectedItem(string itemName, ITimeout timeout = null)
{
    this.GetSelf(timeout).Expand();

    var list = this.GetSelf(timeout).FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List), timeout);
    var listItem = list.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, itemName), timeout);

    listItem.Select();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM