windows之UIAutomation简介
2017-10-26 00:27
1141 查看
1、简介
UIAutomation微软提供的UI自动化库,主要用AutomationElement类来表示UI 自动化目录树中的一个UI自动化元素,.NET Windows的窗体应用程序和WPF应用程序2、体系
在服务端由UIAutomationProvider.dll和UIAutomationTypes.dll提供
在客户端由UIAutomationClient.dll和UIAutomationTypes.dll提供
UIAutomationCore.dll为UI自动化的核心部分,负责Server端和Client端的交互
UIAUtomationClientSideProvides.dll为客户端程序提供自动化支持
3、UI自动化流程
项目中一定要添加引用:使用UISpy查看控件属性值
Process p = Process.Start(@"C:\Windows\system32\calc.exe");//启动应用程序 Thread.Sleep(2000); AutomationElement desktop = AutomationElement.RootElement;//获取RootElement AutomationElement calcframe = desktop.FindFirst(TreeScope.Descendants | TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "计算器"));//获取应用程序 AutomationElement sevenbtn = calcframe.FindFirst(TreeScope.Descendants | TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "7"));//获取控件 InvokePattern ivkp = (InvokePattern)sevenbtn.GetCurrentPattern(InvokePattern.Pattern); ivkp.Invoke(); //触发控件事件
执行效果:
注:PropertyCondition类是用来对相关属性进行条件匹配,在控件树中查找控件时,可以通过最佳匹配来找到相应的控件
4、UIAutomation重要属性
AutomationIdProperty:通过AutomationId来查找AutomationElementNameProperty:通过控件的Name属性来查找AutomationElement
ControlType:通过控件的类型来查找AutomationElement
AutomationId: 唯一地标识自动化元素,将其与同级相区分
Name: WPF 按钮的Content 属性、Win32 按钮的Caption 属性以及 HTML 图像的ALT 属性都映射到 UI 自动化视图中的同一个属性Name
5、TreeScope
Element:指定搜索包括元素本身。Children:指定搜索包括元素的直接子级。
Descendants:指定搜索包括元素的子代(包括子级)。
Parent:指定搜索包括元素的父级。不支持。
Ancestors:指定搜索包括元素的上级
Subtree:指定搜索包括搜索的根和全部子代。
相关文章推荐
- windows之UIAutomation识别UI元素
- windows之UIAutomation的UI元素操作
- MS UI Automation简介
- Windows UI Automation经验
- MS UI Automation简介
- Coded UI Test在Windows Vista、2003和2008上需要Windows Automation API 3.0
- windows之UIAutomation查找元素
- windows之UIAutomation鼠标操作
- MS UI Automation简介
- Web UI Automation with Windows PowerShell
- Windows Azure Pack与VMware VRA 对比(一)VMware vRealize Automation 简介与安装
- 从UI Automation看Windows平台自动化测试原理
- Coded UI Test在Windows Vista、2003和2008上需要Windows Automation API 3.0(转)
- MS UI Automation简介
- MS UI Automation简介
- Vedio for Windows 简介
- windows ssh客户端putty 简介及用其实现windows与linux的文件传输
- 两种改变 Windows Vista UI语言的途径
- UIApplicationMain方法简介
- 一个强大的LogParser的UI工具--logparserlizard简介