用UIAutomation识别UI元素(三)

有时候我们会要捕捉一组有相同属性的控件就要用到AutomationElementCollection 类。

 

AutomationElementCollection 类
表示 AutomationElement 对象的集合
比如我们要捕捉Calculator上的所有Button.
 
 
[c-sharp] view plain copy
  1. using System.Windows.Automation;  
  2.   
  3. ....  
  4.   
  5. //找到Desktop     
  6. AutomationElement Desktop = AutomationElement.RootElement;     
  7. //找到Calculator窗口     
  8. AutomationElement CalcWindows = Desktop.FindFirst(TreeScope.Children,   
  9.     new AndCondition(   
  10.         new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),  
  11.         new PropertyCondition(AutomationElement.ClassNameProperty, "SciCalc")  
  12.         )  
  13.         );  
  14. //找到全部在Calculator子自动化树下的Button控件  
  15. AutomationElementCollection Buttons = CalcWindows.FindAll(TreeScope.Children,  
  16.     new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)  
  17.     );  
AutomationElementCollection主要是通过AutomationElement.FindAll方法获得,
AutomationElement.FindAll的语法和AutomationElement.FindFirst一样.
public AutomationElementCollection FindAll(
	TreeScope scope,
	Condition condition
)

转载来源:http://blog.csdn.net/vbic0673/article/details/6093844

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值