在 TestStack.White 中为 CustomUIItem 的子项获取 IUIItem[]
Getting IUIItem[] for children of CustomUIItem in TestStack.White
一个 WPF 应用程序正在使用一个应用程序框架,我无法编辑它们。
我可以按照以下方式访问 GUI 中的每个元素:
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit((dynamic)item);
}
我的正常控制没有问题,但我用 CustomUIItem
撞墙了。
我想访问它的所有子项,但无法从它们创建新数组 IUIItem[]
。
这是我现在拥有的:
void visit(CustomUIItem item)
{
AutomationElementCollection children =
item
.AutomationElement
.FindAll(TreeScope.Children, Condition.TrueCondition);
UIItemCollection temp = new UIItemCollection(children.Cast<AutomationElement>());
foreach(var t in temp)
{
visit((dynamic)t);
}
}
有时会抛出异常,大多数时候集合仍然是空的。
CusomControl
在其子项中有 "normal" 个控件。
我想要那些常规的 IUIItem
s。
在哪里可以找到这方面的文档。
我唯一找到的是 this,我不能这样做,因为我只是从外部访问,我不知道控件内容。
如果我真的理解了你的问题。
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit(item);
}
我已经更新了您的 visit() 方法,它现在需要一个 IUItem 作为参数以允许访问普通和自定义控件。
public void visit(IUIItem item)
{
if (item is CustomUIItem)
{
// Process custom controls
CustomUIItem customControl = item as CustomUIItem;
// Retrieve all the child controls
IUIItem[] items = customControl.AsContainer().GetMultiple(SearchCriteria.All);
// visit all the children
foreach (var t in items)
{
visit(t);
}
...
}
else
{
// Process normal controls
...
}
}
一个 WPF 应用程序正在使用一个应用程序框架,我无法编辑它们。
我可以按照以下方式访问 GUI 中的每个元素:
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit((dynamic)item);
}
我的正常控制没有问题,但我用 CustomUIItem
撞墙了。
我想访问它的所有子项,但无法从它们创建新数组 IUIItem[]
。
这是我现在拥有的:
void visit(CustomUIItem item)
{
AutomationElementCollection children =
item
.AutomationElement
.FindAll(TreeScope.Children, Condition.TrueCondition);
UIItemCollection temp = new UIItemCollection(children.Cast<AutomationElement>());
foreach(var t in temp)
{
visit((dynamic)t);
}
}
有时会抛出异常,大多数时候集合仍然是空的。
CusomControl
在其子项中有 "normal" 个控件。
我想要那些常规的 IUIItem
s。
在哪里可以找到这方面的文档。 我唯一找到的是 this,我不能这样做,因为我只是从外部访问,我不知道控件内容。
如果我真的理解了你的问题。
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit(item);
}
我已经更新了您的 visit() 方法,它现在需要一个 IUItem 作为参数以允许访问普通和自定义控件。
public void visit(IUIItem item)
{
if (item is CustomUIItem)
{
// Process custom controls
CustomUIItem customControl = item as CustomUIItem;
// Retrieve all the child controls
IUIItem[] items = customControl.AsContainer().GetMultiple(SearchCriteria.All);
// visit all the children
foreach (var t in items)
{
visit(t);
}
...
}
else
{
// Process normal controls
...
}
}