public AutomationElement FindMatchingChild(Predicate <AutomationElement> pred)
        {
            IUIAutomationTreeWalker walker;

            pAutomation.get_ControlViewWalker(out walker);
            try {
                IUIAutomationElement elem;
                walker.GetFirstChildElement(pElement, out elem);
                while (elem != null)
                {
                    AutomationElement ae = new AutomationElement(elem);
                    if (pred(ae))
                    {
                        return(ae);
                    }
                    IUIAutomationElement next;
                    walker.GetNextSiblingElement(elem, out next);
                    elem = next;
                }
                return(null);
            }
            finally {
                if (walker != null)
                {
                    Marshal.ReleaseComObject(walker);
                }
            }
        }
        public IUIAutomationTreeWalker CreateTreeWalker()
        {
            IUIAutomationTreeWalker walker;

            pAutomation.get_ControlViewWalker(out walker);
            return(walker);
        }