用UIAutomation识别UI元素(二)

来源:互联网 发布:数据库故障分为哪几种 编辑:程序博客网 时间:2024/06/05 08:02

识别UI元素

找到窗口就可以开始找窗口上的UI元素了。

 

比如我想找Calculator上的文本框

 

 可以用如下代码实现:

 

 

 

 AutomationElement.FindFirst 的方法

 

public AutomationElement FindFirst(TreeScope scope,Condition condition)

 

TreeScope是个枚举类型

成员名称

说明

Element

指定搜索包括元素本身。

Children

指定搜索包括元素的直接子级。

Descendants

指定搜索包括元素的子代(包括子级)。

Parent

指定搜索包括元素的父级。不支持。

Ancestors

指定搜索包括元素的上级(包括��级)。不支持

Subtree

指定搜索包括搜索的根和全部子代。

Children和Descendants比较常用。Subtree也用比较多。

 Condition 类

 在 UI 自动化目录树中搜索元素时应用于筛选的条件的基类型。

 

主要都使用下面几个子类

    System.Windows.Automation.AndCondition
    System.Windows.Automation.NotCondition
    System.Windows.Automation.OrCondition
    System.Windows.Automation.PropertyCondition

 

AndCondition 表示一个与(And)条件
NotCondition 表示一个非(Not)条件

OrCondition 表示一个或(Or)条件

 

PropertyCondition 它测试属性是否具有指定的值

 

可以在UISpy的右边Identification中找到相应的值。

一般用ControlType,ClassName, Automationid 和 Name 就够用了。其他的一般较少使用。

 

 

 

 

 

 




 

原创粉丝点击