如何从 UITestControl 获取 ItemStatus?
-
13-09-2019 - |
解决方案
看的编码的UI测试生成WpfControl
代码。它有一个属性,NativeElement。此属性是一个AutomationElement
。
public abstract class WpfControl : UITestControl
{
...
public virtual object NativeElement
{
get
{
return ((object)(this.GetProperty(UITestControlProperties.Common.NativeElement)));
}
}
...
}
您可以编写扩展方法来投,并得到ItemStatus。
public static string GetItemStatus(this WpfControl control)
{
var automationElement = (AutomationElement)control.NativeElement;
return automationElement.Current.ItemStatus;
}
我不能肯定为什么NativeElement记录为object
(这使得吸气剂浇铸冗余)。所有的WPF控件NativeElement的类型AutomationElement
的。我建议编辑所生成的代码和简单地直接调用control.NativeElement.Current.ItemStatus
。
不隶属于 StackOverflow