How do I get ItemStatus from a UITestControl?

≯℡__Kan透↙ 提交于 2019-12-06 05:34:36

Look at the Coded UI Tests generated code for WpfControl. It has a property, NativeElement. This property is an AutomationElement.

public abstract class WpfControl : UITestControl
{
    ...

    public virtual object NativeElement
    {
        get
        {
            return ((object)(this.GetProperty(UITestControlProperties.Common.NativeElement)));
        }
    }

    ...
}

You can write an extension method to cast it and get ItemStatus.

public static string GetItemStatus(this WpfControl control)
{
    var automationElement = (AutomationElement)control.NativeElement;
    return automationElement.Current.ItemStatus;
}

I am not certain why NativeElement is recorded as an object (which makes the getter cast redundant). All WPF controls' NativeElement are of type AutomationElement. I would suggest editing the generated code and simply calling control.NativeElement.Current.ItemStatus directly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!