Exemplo n.º 1
0
        AutomationElement GetWindow(string LocValCal) //*******
        {
            UIAComWrapperHelper UIA = new UIAComWrapperHelper();

            List <object> AppWindows = UIA.GetListOfWindows();


            foreach (AutomationElement window in AppWindows)
            {
                string WindowTitle = UIA.GetWindowInfo(window);

                if (WindowTitle == null)
                {
                    WindowTitle = "";
                }
                Reporter.ToLog(eLogLevel.INFO, $"Method - {MethodBase.GetCurrentMethod().Name}, WindowTitle - {WindowTitle}");
                switch (LocateBy)
                {
                case eLocateBy.ByTitle:
                    if (WindowTitle.Contains(LocValCal))
                    {
                        return(window);
                    }
                    break;

                case eLocateBy.ByClassName:
                    if (window.Current.ClassName.Equals(LocValCal))
                    {
                        return(window);
                    }
                    break;
                }
            }
            return(null);
        }
        private bool FindProcessWindowTitle(Process p, string waitForWindowTilte)//no need to get all windows.
        {
            TreeWalker          walker   = TreeWalker.ControlViewWalker;
            AutomationElement   window   = walker.GetFirstChild(AutomationElement.RootElement);
            UIAComWrapperHelper uiHelper = new UIAComWrapperHelper();

            while (window != null)
            {
                if (window.Current.ProcessId == p.Id)
                {
                    String WindowTitle = "";
                    WindowTitle = uiHelper.GetWindowInfo(window);
                    if (!string.IsNullOrEmpty(WindowTitle))
                    {
                        if (WindowTitle.ToLower().Contains(waitForWindowTilte.ToLower()))
                        {
                            return(true);
                        }
                    }
                }
                try
                {
                    window = walker.GetNextSibling(window);
                }
                catch (Exception ex)
                {
                    Reporter.ToLog(eLogLevel.ERROR, "Exception in FindProcessWindowTitle", ex);
                }
            }
            return(false);
        }