[英]Getting IUIItem[] for children of CustomUIItem in TestStack.White
A WPF Application is using an Application Framework and I can edit neither of them. WPF应用程序正在使用应用程序框架,而我都不能编辑它们。
I can visit every element in the GUI doing something along these lines: 我可以按照以下步骤访问GUI中的每个元素:
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit((dynamic)item);
}
I have no Issue with normal controls but I hit a wall with CustomUIItem
. 我对常规控件没有任何问题,但是我遇到了
CustomUIItem
。
I would like to visit all the Children of it but I fail to make a new array IUIItem[]
from them. 我想访问它的所有子项,但是无法从中创建一个新的数组
IUIItem[]
。
Here is what I have now: 这是我现在所拥有的:
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 this throws and most of the time collection remains empty. 这样抛出的东西,大多数时间集合保持空白。
The CusomControl
has "normal" controls among its children. CusomControl
在其子CusomControl
具有“常规”控件。 I want those as regular IUIItem
s. 我想要那些作为常规
IUIItem
。
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.
我发现的唯一内容是this ,我无法做到这一点,因为我只是从外部访问,而且我不知道控件的内容。
If i have really understood your problem. 如果我真的了解你的问题。
IUIItem[] items = window.GetMultiple(SearchCriteria.All);
foreach (var item in items)
{
visit(item);
}
I have update your visit() method, it takes now a IUItem as argument to allow visiting of normal and custom controls. 我已经更新了您的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
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.