简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM