Ejemplo n.º 1
0
        /// <summary>
        /// Finds the child by navigating into the logical hierarchy
        /// </summary>
        /// <param name="paccParent">Parent window as IAccessible</param>
        /// <param name="childId">ID of child window</param>
        /// <param name="childWindow">Child window description</param>
        /// <param name="ppaccChild">Child as IAccessible</param>
        /// <param name="foundId">ID found for child</param>
        /// <returns>flag if child found</returns>
        public static bool FindChild(IAccessible paccParent, int childId, PopupBasherConfiguration.PopupConfigChild childWindow, out IAccessible ppaccChild, out int foundId)
        {
            bool found = false;

            ppaccChild = null;
            foundId    = 0;

            try
            {
                // First check if the parent is the search item
                found = IsMatching(paccParent, childId, childWindow);
                if (found)
                {
                    ppaccChild = paccParent;
                    foundId    = childId;
                }
                else
                {
                    int      numChildren = paccParent.accChildCount;
                    object[] children    = new object[numChildren];
                    NativeMethods.AccessibleChildren(paccParent, 0, numChildren, children, out numChildren);

                    foreach (object child in children)
                    {
                        if (child is int)
                        {
                            // This is an element
                            found = IsMatching(paccParent, (int)child, childWindow);
                            if (found)
                            {
                                ppaccChild = paccParent;
                                foundId    = (int)child;
                            }
                        }
                        else if (child is IAccessible)
                        {
                            found = FindChild((IAccessible)child, 0, childWindow, out ppaccChild, out foundId);
                        }

                        if (found)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracing.WriteDebugTextWarning(Tracing.ComponentId.ExcelDriver, ex.ToString());
            }

            return(found);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if child window matches description in popup basher config
        /// </summary>
        /// <param name="acc">Parent as IAccessible</param>
        /// <param name="childId">ID of child window</param>
        /// <param name="childWindow">description of child window to look for</param>
        /// <returns>True if child matches description, false otherwise</returns>
        private static bool IsMatching(IAccessible acc, int childId, PopupBasherConfiguration.PopupConfigChild childWindow)
        {
            string classStr, nameStr, roleStr;
            uint   roleRef = 0;
            bool   found   = false;
            IntPtr hwnd    = (IntPtr)0;

            // First check if the parent is the search item
            roleStr = GetUIElementRole(acc, childId, ref roleRef);
            NativeMethods.WindowFromAccessibleObject(acc, ref hwnd);
            if ((uint)childWindow.Role == roleRef)
            {
                classStr = GetWindowClassForUIElement(acc);
                if ((childWindow.ClassName == null) || (String.Compare(classStr, childWindow.ClassName, true, CultureInfo.CurrentCulture) == 0))
                {
                    // If no name was specified, always treat this as a match
                    if (childWindow.Title == null)
                    {
                        found = true;
                    }
                    else
                    {
                        nameStr = GetUIElementName(acc, childId);
                        if (nameStr != null)
                        {
                            if (nameStr.Length > 0)
                            {
                                switch (childWindow.Search)
                                {
                                case PopupBasherConfiguration.SearchMode.Exact:
                                    found = String.Compare(nameStr, childWindow.Title, true, CultureInfo.CurrentCulture) == 0;
                                    break;

                                case PopupBasherConfiguration.SearchMode.RegEx:
                                    Regex r;

                                    r     = new Regex(childWindow.Title, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                                    found = r.IsMatch(nameStr);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(found);
        }