//要确定一个界面元素主要的参数有以下几个:ControlName、Localized、ControlTypeName、AutomationId
//自动化元素的类定义
private ControlType controlType;
private string name;
private string localizedControlType;
private string automationId;
public ElementDefine(ControlType conType, string name, string LCtype,
string automationId)
{
this.controlType = conType;
this.name = name;
this.localizedControlType = LCtype;
this.automationId = automationId;
}
public ControlType ControlType { get { return controlType; } set { } }
public string Name { get { return name; } set { } }
public string LocalizedControlType { get { return localizedControlType;
} set { } }
public string AutomationId { get { return automationId; } set { }
//根据对象属性返回对象的方法
Public AutomationElement GetElementByDescendants(AutomationElement
parentWindowHandle){…}
//根据controlPattern定义的方法
public bool ElementInvoke(AutomationElement
ipe)//invoke pattern element
public bool
ElementValuePattern(AutomationElement vpe, string value)//value pattern element
public bool
ElementTextPattern(AutomationElement tpe, string value)//text pattern element
…
}
//UI界面元素对象初始化:
ElementDefine
loginElement = new ElementDefine(ControlType.Button, "用户登录",
"按钮",””);//构造函数中对元素的参数进行初始化