查看代码化的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
(这使得getter投射多余)。所有WPF控件的NativeElement的类型都是
自动元件
. 我建议编辑生成的代码并简单地调用
control.NativeElement.Current.ItemStatus
直接。