Пример #1
0
        public bool Exists(Func <ConditionFactory, ConditionBase> conditionFunc, TimeSpan timeout, TimeSpan offscreenTimeout, bool checkOnScreen = true, ISHAutomationElement parent = null, bool xpathOnly = false)
        {
            bool exists                  = true;
            bool regenerateXPath         = false;
            ISHAutomationElement control = null;

            if (parent == null)
            {
                control = GetXPathElementFromCondition(conditionFunc, timeout);
                if (control == null && !xpathOnly)
                {
                    regenerateXPath = true;
                    control         = FindFirstDescendant(conditionFunc, timeout: timeout);
                }
            }
            else
            {
                if (xpathOnly)
                {
                    throw new InvalidOperationException("Cannot search with xpath using parent");
                }
                control = parent.FindFirstDescendant(conditionFunc, timeout: timeout);
            }

            if (control == null)
            {
                exists = false;
            }
            else if (checkOnScreen)
            {
                control.WaitUntilPropertyEquals(PropertyId.Register(AutomationType.UIA3, 30022, "IsOffscreen"), false, offscreenTimeout);

                exists = control.IsOnscreen;
            }

            if (parent == null)
            {
                SaveXPathFromControl((SHAutomationElement)control, conditionFunc, regenerateXPath);
            }

            return(exists);
        }