TestStack 白色 GetParent 元素
TestStack White GetParent Element
这是一个由两部分组成的问题:
1) 我正在尝试定位元素的父元素,以便它可以是基于某些属性(如 controlType)的当前元素的任何祖父元素。
代码:
control.GetParent<IUIItem>();
上面的代码给了我 "control" 元素的直接父级而不是我想要的授予父级
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 方法中,当我试图获取父元素的类型时,它 returning 是这样的:
Castle.Proxies.TabProxy
但我期望 GetType 将 return me "Tab" 作为控件的类型。不确定为什么 returns Castle.Proxies.TabProxy。我想知道是否有任何方法可以识别元素的控件类型,以便可以将其转换为相关的控件类型。
我是 C# 新手
GetType returns 控件的 System.Type 而不是实际的控件类型。您可以像这样找出控件的控件类型:
AutomationElement element = control.AutomationElement;
ControlType elementType = element.Current.ControlType;
要获取父级的控件类型,您可以使用此代码:
AutomationElement parent = TreeWalker.RawViewWalker.GetParent(control.AutomationElement);
ControlType parentType = parent.Current.ControlType;
这是一个由两部分组成的问题:
1) 我正在尝试定位元素的父元素,以便它可以是基于某些属性(如 controlType)的当前元素的任何祖父元素。
代码:
control.GetParent<IUIItem>();
上面的代码给了我 "control" 元素的直接父级而不是我想要的授予父级
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 方法中,当我试图获取父元素的类型时,它 returning 是这样的: Castle.Proxies.TabProxy 但我期望 GetType 将 return me "Tab" 作为控件的类型。不确定为什么 returns Castle.Proxies.TabProxy。我想知道是否有任何方法可以识别元素的控件类型,以便可以将其转换为相关的控件类型。 我是 C# 新手
GetType returns 控件的 System.Type 而不是实际的控件类型。您可以像这样找出控件的控件类型:
AutomationElement element = control.AutomationElement;
ControlType elementType = element.Current.ControlType;
要获取父级的控件类型,您可以使用此代码:
AutomationElement parent = TreeWalker.RawViewWalker.GetParent(control.AutomationElement);
ControlType parentType = parent.Current.ControlType;