[英]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
在其子CusomControl
具有“常規”控件。 我想要那些作為常規IUIItem
。
在哪里可以找到此文檔。 我發現的唯一內容是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
...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.