Approachs to Find AutomationElement by Tree Structure

 Approach 1:

AutomationElement item1 = TreeWalker.ContentViewWalker.GetFirstChild(item); 

item1 = TreeWalker.ContentViewWalker.GetFirstChild(item1);
item1 = TreeWalker.ContentViewWalker.GetNextSibling(item1);
AutomationElement autoElement1 = FindChildElement("textBoxPath", item);

 

Note:

// Summary:
 //     Represents a predefined System.Windows.Automation.TreeWalker containing a
 //     view of elements in the tree that are marked as content controls.
 ContentViewWalker;
 //
 // Summary:
 //     Represents a predefined System.Windows.Automation.TreeWalker containing a
 //     view of elements in the tree that are marked as controls.
ControlViewWalker;
  //
// Summary:
//     Represents a predefined System.Windows.Automation.TreeWalker containing a
//     view of all the elements in the tree.

RawViewWalker; 

 

Approach 2: 

Condition propCondition = new PropertyCondition( AutomationElement.AutomationIdProperty, controlIDorName, PropertyConditionFlags.IgnoreCase);
 // Find the element.

rootElement.FindFirst(TreeScope.Descendants, propCondition); 

posted @ 2011-04-07 11:19  Longmarch2008  阅读(313)  评论(0编辑  收藏  举报