Getting IUIItem[] for children of CustomUIItem in TestStack.White

不打扰是莪最后的温柔 提交于 2019-12-24 02:16:25

问题


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 IUIItems.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!