【问题标题】:TestStack White GetParent ElementTestStack 白色 GetParent 元素
【发布时间】:2016-05-27 15:25:32
【问题描述】:

这是一个两部分的问题:
1)我正在尝试定位元素的父元素,使其可以是基于某些属性(如 controlType)的当前元素的任何祖父元素。 代码:

control.GetParent<IUIItem>();

上面的代码给了我“控制”元素的直接父级,而不是我想要的授权父级

control.GetParent<Tab>();

从这里我知道这个 API 需要事先知道父元素类型。
2)因此,我尝试为此创建某种自己的实用程序:

public static IUIItem GetParent(ControlType type, IUIItem control)
        {
            while (true) {
                control = control.GetParent<IUIItem>();
                Console.WriteLine(control.GetType());
                if (control.GetType().IsInstanceOfType(type)) {
                    Console.WriteLine("Found match");
                    break;
                }
            }
            return control;
        }

所以在上面的 Util 方法中,当我试图获取父元素的类型时,它会返回如下内容: Castle.Proxies.TabProxy 但我期待 GetType 将“Tab”作为控件的类型返回给我。不知道为什么它返回 Castle.Proxies.TabProxy。我想知道是否有任何方法可以识别元素的控件类型,以便可以将其转换为相关的控件类型。 我是 C# 新手

【问题讨论】:

    标签: c# ui-automation white-framework


    【解决方案1】:

    GetType 返回控件的 System.Type,而不是实际的控件类型。您可以像这样找出控件的控件类型:

    AutomationElement element = control.AutomationElement;
    ControlType elementType =   element.Current.ControlType;
    

    要获取父级的控件类型,您可以使用以下代码:

    AutomationElement parent = TreeWalker.RawViewWalker.GetParent(control.AutomationElement);
    ControlType parentType = parent.Current.ControlType;
    

    【讨论】:

    • 你让我成为了一天的伙伴..Thnx 很多。
    猜你喜欢
    • 2015-05-11
    • 2015-09-19
    • 2018-09-06
    • 2016-01-11
    • 2015-12-14
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多