在一般情况下用FindFirst和FindAll只可以找到在UISpy中的Control View中有显示的AutomationElement。
但是有时候有的AutomationElement在Control View没有显示,但是在Raw View中确存在。特别容易出现在自定义控件中。
在一个Treeview中就每有一个Text AutomationElement只在RAW View中有显示。
这时候我们可以用TreeWalker 类查找在Raw View中的AutomationElement。
- string get_itemname(AutomationElement n)
- {
- //在AutomationElement中找子Element
- for (AutomationElement elementNode = TreeWalker.RawViewWalker.GetFirstChild(n); elementNode != null; elementNode = TreeWalker.RawViewWalker.GetNextSibling(elementNode))
- {
- //判断AutomationElement的类型
- if (elementNode.Current.ControlType.ProgrammaticName == "ControlType.Text")
- {
- return elementNode.Current.Name;
- }
- }
- return "";
- }
转载来源:http://blog.csdn.net/vbic0673/article/details/6096381