用UIAutomation识别UI元素(一)

 

用UIAutomation识别UI元素(一)

UIAutomtion中主要用AutomationElement 类来 表示 UI 自动化目录树中的一个 UI 自动化元素,并包含由 UI 自动化客户端应用程序用作标识符的值。

 

 

添加UIAutomation

在reference中添加UIAutomationClient,UIAutomationTypes,UIAutomationProvider 和UIAutomationClientsideProviders。

(Donet 3.0以上的项目中才有)

 

如何识别一个窗口。

先启动calc.exe.

[c-sharp]  view plain copy
  1. using System.Diagnostics;  
  2. using System.Windows.Automation;  
  3. ...  
  4.  void GetCalc()  
  5. {  
  6. //通过Process的Handle获得AutomationElement  
  7. Process[] p = Process.GetProcessesByName("calc");  
  8. AutomationElement CalcWindows = AutomationElement.FromHandle(p[0].MainWindowHandle);  
  9. }  

还有一种方法

[c-sharp]  view plain copy
  1. using System.Windows.Automation;  
  2. ...  
  3.  void GetCalc()  
  4. {  
  5. //先识别桌面,再在桌面中查找Window类型且名字叫"Calculator"(英文系统)  
  6. AutomationElement RootElement=AutomationElement.RootElement;  
  7. AutomationElement CalcWindows=RootElement.FindFirst(TreeScope.Children,  
  8. new AndCondition(  
  9. new PropertyCondition(AutomationElement.ControlTypeProperty,ControlType.Window),  
  10. new PropertyCondition(AutomationElement.NameProperty,"Calculator")  
  11.                  ));                                                                     




转载来源:http://blog.csdn.net/vbic0673/article/details/6089375
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值