我试图使用根据它的值来选择一个项。
我有一个类ComboBox,它继承自UIAutomation.Element。
此外,我在这个combobox元素上有一个方法,应该可以用一个string调用它来选择匹配的combobox项。
我试过以下几种方法:
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似乎无法使用这种类型.
你知道如何取回正确的物品吗?
还是我做错了什么?
提前感谢
发布于 2015-09-24 07:00:40
由于@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();
}https://stackoverflow.com/questions/32741949
复制相似问题