public ISHAutomationElement FindFirstDescendant(ConditionBase condition, TimeSpan timeout, bool waitUntilExists = true) { SHAutomationElement element = null; bool getElement(bool shouldExist) { if ((shouldExist && element == null) || (!shouldExist && element != null)) { element = FindFirstDescendantBase(condition); } return(shouldExist ? element?.FrameworkAutomationElement != null : element == null); } getElement(true); if (element == null && waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElement(waitUntilExists), timeout); } else if (element != null && !waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElement(waitUntilExists), timeout); } return(element?.FrameworkAutomationElement != null ? element : null); }
public ISHAutomationElement FindFirstChild(TimeSpan timeout, bool waitUntilExists = true) { SHAutomationElement element = null; bool getElement(bool shouldExist) { if (element == null) { element = FindFirstChildBase(); } return(shouldExist ? element?.FrameworkAutomationElement != null : element == null); } getElement(waitUntilExists); if (element == null && waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElement(true), timeout); } else if (element != null && !waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElement(false), timeout); } return(element?.FrameworkAutomationElement != null ? element : null); }
public ISHAutomationElement[] FindAllWithOptions(TreeScope treeScope, ConditionBase condition, TreeTraversalOption traversalOptions, SHAutomationElement root, TimeSpan timeout, bool waitUntilExists = true) { List <SHAutomationElement> elements = new List <SHAutomationElement>(); bool getElements(bool shouldExist) { if (!elements.Any()) { elements = FindAllWithOptionsBase(treeScope, condition, traversalOptions, root).Where(x => x.FrameworkAutomationElement != null).ToList(); } return(shouldExist ? elements.Any() : !elements.Any()); } getElements(waitUntilExists); if (!elements.Any() && waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElements(true), timeout); } else if (elements.Any() && !waitUntilExists && timeout.TotalMilliseconds > 0) { SHSpinWait.SpinUntil(() => getElements(false), timeout); } if (elements != null && elements.Any()) { return(elements.ToArray()); } return(Array.Empty <SHAutomationElement>()); }
public ISHAutomationElement[] FindAllWithOptions(TreeScope treeScope, ConditionBase condition, TreeTraversalOption traversalOptions, SHAutomationElement root) { return(FindAllWithOptions(treeScope, condition, traversalOptions, root, TimeSpan.FromSeconds(20))); }
/// <summary> /// Finds the first matching element in the specified order. /// </summary> public SHAutomationElement FindFirstWithOptionsBase(TreeScope treeScope, ConditionBase condition, TreeTraversalOption traversalOptions, SHAutomationElement root) { try { return(FrameworkAutomationElement.FindFirstWithOptions(treeScope, condition, traversalOptions, root)); } catch (System.Runtime.InteropServices.COMException) { return(null); } }