问题描述
WPF应用程序正在使用应用程序框架,而我都不能编辑它们.
A WPF Application is using an Application Framework and I can edit neither of them.
我可以按照以下步骤访问GUI中的每个元素:
I can visit every element in the GUI doing something along these lines:
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit((dynamic)item);
}
我对常规控件没有任何问题,但是我却用CustomUIItem
碰壁了.
I have no Issue with normal controls but I hit a wall with CustomUIItem
.
我想访问它的所有子级,但是我无法从它们中创建一个新的数组IUIItem[]
.
I would like to visit all the Children of it but I fail to make a new array IUIItem[]
from them.
这是我现在拥有的:
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);
}
}
这种方法会抛出Somethimes,并且大多数时候收集都保持为空.
Somethimes this throws and most of the time collection remains empty.
CusomControl
在其子级中具有正常"控件.我希望这些作为常规的IUIItem
.
The CusomControl
has "normal" controls among its children.I want those as regular IUIItem
s.
在哪里可以找到此文档.我发现的唯一内容是此,我不能这样做,因为我只是从外面访问,我不知道控件的内容.
Where can I find the documentation for this.The only thing I found was this, and I can not do that since I am only visiting from outside and I do not know the controls content.
推荐答案
如果我真的了解您的问题.
If i have really understood your problem.
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit(item);
}
我已经更新了您的visit()方法,现在它以IUItem作为参数来允许访问常规控件和自定义控件.
I have update your visit() method, it takes now a IUItem as argument to allow visiting of normal and custom controls.
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
...
}
}
这篇关于在TestStack.White中为CustomUIItem的子级获取IUIItem []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!