问题
A WPF Application is using an Application Framework and I can edit neither of them.
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);
}
I have no Issue with normal controls but I hit a wall with CustomUIItem
.
I would like to visit all the Children of it but I fail to make a new array IUIItem[]
from them.
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.
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.
回答1:
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.
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
...
}
}
来源:https://stackoverflow.com/questions/41881079/getting-iuiitem-for-children-of-customuiitem-in-teststack-white