搜索
您的当前位置:首页正文

UIAutomation学习入门

来源:知库网
UIAutomation学习⼊门

⼀.界⾯的⾃动化操作.Ui⾃动化测试.软件外挂

⼆.Win32基础知识

a.Win32中⼀切元素皆窗⼝,窗⼝之间有⽗⼦关系。整个桌⾯是⼀个“根窗⼝”。b.进程:

根据进程id拿到进程对象Process process = Process.GetProcessById(processId);启动⼀个进程:Process process = Process.Start(exe路径);杀死⼀个进程process.Kill()

三.UIAutonation基础

1、需要添加对UIAutomationClient、 UIAutomationProvider、 UIAutomationTypes的引⽤2、AutomationElement.RootElement是窗⼝根元素

AutomationElement.FromHandle(IntPtr hwnd)从窗⼝句柄拿到AutomationElement对象。3、遍历:

mainElement.FindAll(TreeScope.Descendants,

new PropertyCondition(AutomationElement.ClassNameProperty, \"TLabeledEdit\"));

TreeScope.Descendants代表递归从所有⼦孙元素中递归查找;如果是从直接⼦节点查找,则使⽤TreeScope.Children。Condition是过滤条件,可以根据类名等查找,如果是不指定查询条件则使⽤Condition.True Condition。FindFirst是查到第⼀个。

4、点击按钮、设置⽂本、读取⽂本使⽤Pattern来实现。不是所有Pattern都⽀持1)设置控件的值ValuePattern

valuePattern = (ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern);valuePattern.SetValue(\"rupeng.com\");2)得到⽂本控件的值TextPattern

valuePattern = (TextPattern)element.GetCurrentPattern(TextPattern.Pattern);string v= valuePattern.DocumentRange.GetText(-1);3)调⽤控件,⽐如点击按钮

var clickPattern = (InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern);clickPattern.Invoke();

因篇幅问题不能全部显示,请点此查看更多更全内容

Top