public static IUiElement PerformNavigateToNextSibling(this IUiElement element) { IUiElement result = null; var walker = new classic.TreeWalker(classic.Condition.TrueCondition); try { result = AutomationFactory.GetUiElement(walker.GetNextSibling(element.GetSourceElement() as classic.AutomationElement)); } catch { } return result; }
public static IUiElement GetParent(this IUiElement element) { IUiElement result = null; var walker = new classic.TreeWalker( classic.Condition.TrueCondition); try { result = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement)); } catch {} return result; }
protected void GetAutomationElementsChildren(IUiElement inputObject, bool firstChild) { if (!CheckAndPrepareInput(this)) { return; } var walker = new classic.TreeWalker( classic.Condition.TrueCondition); IUiElement sibling = firstChild ? AutomationFactory.GetUiElement(walker.GetFirstChild(inputObject.GetSourceElement() as classic.AutomationElement)) : AutomationFactory.GetUiElement(walker.GetLastChild(inputObject.GetSourceElement() as classic.AutomationElement)); WriteObject(this, sibling); }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <returns></returns> internal static IUiElement GetAncestorWithHandle(this IUiElement element) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* TreeWalker walker = new TreeWalker( System.Windows.Automation.Condition.TrueCondition); */ try { // 20140102 // IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement())); IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement)); while (testparent != null && // 20143012 // testparent.Current.NativeWindowHandle == 0) { testparent.GetCurrent().NativeWindowHandle == 0) { testparent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement() as classic.AutomationElement)); if (testparent != null && // 20143012 // (int)testparent.Current.ProcessId > 0 && // testparent.Current.NativeWindowHandle != 0) { (int)testparent.GetCurrent().ProcessId > 0 && testparent.GetCurrent().NativeWindowHandle != 0) { return testparent; } } // 20143012 // return testparent.Current.NativeWindowHandle != 0 ? testparent : null; return testparent.GetCurrent().NativeWindowHandle != 0 ? testparent : null; } catch { return null; } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <returns></returns> internal static IUiElement GetAncestorWithHandle(this IUiElement element) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* * TreeWalker walker = * new TreeWalker( * System.Windows.Automation.Condition.TrueCondition); */ try { // 20140102 // IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement())); IUiElement testparent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement)); while (testparent != null && // 20143012 // testparent.Current.NativeWindowHandle == 0) { testparent.GetCurrent().NativeWindowHandle == 0) { testparent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testparent.GetSourceElement() as classic.AutomationElement)); if (testparent != null && // 20143012 // (int)testparent.Current.ProcessId > 0 && // testparent.Current.NativeWindowHandle != 0) { (int)testparent.GetCurrent().ProcessId > 0 && testparent.GetCurrent().NativeWindowHandle != 0) { return(testparent); } } // 20143012 // return testparent.Current.NativeWindowHandle != 0 ? testparent : null; return(testparent.GetCurrent().NativeWindowHandle != 0 ? testparent : null); } catch { return(null); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="scope"></param> /// <returns></returns> internal static IUiElement[] GetParentOrAncestor(this IUiElement element, classic.TreeScope scope) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); var ancestors = new List<IUiElement>(); try { IUiElement testParent = AutomationFactory.GetUiElement(walker.GetParent(element.GetSourceElement() as classic.AutomationElement)); if (scope == classic.TreeScope.Parent || scope == classic.TreeScope.Ancestors) { if (testParent.GetCurrent() != UiElement.RootElement.GetCurrent()) { ancestors.Add(testParent); } if ((testParent.Equals(UiElement.RootElement) && testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) || scope == classic.TreeScope.Parent) { return ancestors.ToArray(); } } while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0 && !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) { testParent = AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)); if (testParent != null && (int)testParent.GetCurrent().ProcessId > 0 && !testParent.GetCurrent().Equals(UiElement.RootElement.GetCurrent())) { ancestors.Add(testParent); } else { break; } } return ancestors.ToArray(); } catch { return ancestors.ToArray(); } }
/// <summary> /// /// </summary> /// <param name="cmdlet"></param> /// <param name="element"></param> internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* TreeWalker walker = new TreeWalker( System.Windows.Automation.Condition.TrueCondition); */ try { // commented out 201206210 //testparent = // walker.GetParent(element); IUiElement testParent = element; // 20140312 // while (testParent != null && (int)testParent.Current.ProcessId > 0) { while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0) { testParent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)); // 20140312 // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue; if (testParent == null || (int) testParent.GetCurrent().ProcessId <= 0) continue; if (testParent == cmdlet.OddRootElement) { testParent = null; } else{ string parentControlType = // getControlTypeNameOfAutomationElement(testparent, element); // testparent.Current.ControlType.ProgrammaticName.Substring( // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); // // experimental // 20140312 // testParent.Current.ControlType.ProgrammaticName.Substring( // testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); testParent.GetCurrent().ControlType.ProgrammaticName.Substring( testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1); // // if (parentControlType.Length == 0) { // break; //} // in case this element is an upper-level Pane // residing directrly under the RootElement // change type to window // i.e. Get-UiaPane - > Get-UiaWindow // since Get-UiaPane is unable to get something more than // a window's child pane control if (parentControlType == "Pane" || parentControlType == "Menu") { // 20131109 //if (walker.GetParent(testParent) == cmdlet.rootElement) { // 20131112 //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) { // 20131118 // property to method //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) { // 20140102 // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) { if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement) { parentControlType = "Window"; } } string parentVerbosity = @"Get-Uia" + parentControlType; try { // 20140312 // if (testParent.Current.AutomationId.Length > 0) { // parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'"); if (testParent.GetCurrent().AutomationId.Length > 0) { parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'"); } } catch { } if (!cmdlet.NoClassInformation) { try { // 20140312 // if (testParent.Current.ClassName.Length > 0) { // parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'"); if (testParent.GetCurrent().ClassName.Length > 0) { parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'"); } } catch { } } try { // 20140312 // if (testParent.Current.Name.Length > 0) { // parentVerbosity += (" -Name '" + testParent.Current.Name + "'"); if (testParent.GetCurrent().Name.Length > 0) { parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'"); } } catch { } if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity) continue; cmdlet.LastRecordedItem.Add(parentVerbosity); cmdlet.WriteVerbose(parentVerbosity); } } } catch (Exception eErrorInTheInnerCycle) { cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message); // _errorMessageInTheInnerCycle = errorMessage = eErrorInTheInnerCycle.Message; // _errorInTheInnerCycle = true; errorOccured = true; } }
/// <summary> /// /// </summary> /// <param name="cmdlet"></param> /// <param name="element"></param> internal static void CollectAncestors(this IUiElement element, TranscriptCmdletBase cmdlet, ref string errorMessage, ref bool errorOccured) { var walker = new classic.TreeWalker( classic.Condition.TrueCondition); /* * TreeWalker walker = * new TreeWalker( * System.Windows.Automation.Condition.TrueCondition); */ try { // commented out 201206210 //testparent = // walker.GetParent(element); IUiElement testParent = element; // 20140312 // while (testParent != null && (int)testParent.Current.ProcessId > 0) { while (testParent != null && (int)testParent.GetCurrent().ProcessId > 0) { testParent = // 20140102 // AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())); AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)); // 20140312 // if (testParent == null || (int) testParent.Current.ProcessId <= 0) continue; if (testParent == null || (int)testParent.GetCurrent().ProcessId <= 0) { continue; } if (testParent == cmdlet.OddRootElement) { testParent = null; } else { string parentControlType = // getControlTypeNameOfAutomationElement(testparent, element); // testparent.Current.ControlType.ProgrammaticName.Substring( // element.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); // // experimental // 20140312 // testParent.Current.ControlType.ProgrammaticName.Substring( // testParent.Current.ControlType.ProgrammaticName.IndexOf('.') + 1); testParent.GetCurrent().ControlType.ProgrammaticName.Substring( testParent.GetCurrent().ControlType.ProgrammaticName.IndexOf('.') + 1); // // if (parentControlType.Length == 0) { // break; //} // in case this element is an upper-level Pane // residing directrly under the RootElement // change type to window // i.e. Get-UiaPane - > Get-UiaWindow // since Get-UiaPane is unable to get something more than // a window's child pane control if (parentControlType == "Pane" || parentControlType == "Menu") { // 20131109 //if (walker.GetParent(testParent) == cmdlet.rootElement) { // 20131112 //if ((new UiElement(walker.GetParent(testParent.SourceElement))) == cmdlet.oddRootElement) { // 20131118 // property to method //if (ObjectsFactory.GetUiElement(walker.GetParent(testParent.SourceElement)) == cmdlet.oddRootElement) { // 20140102 // if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement())) == cmdlet.OddRootElement) { if (AutomationFactory.GetUiElement(walker.GetParent(testParent.GetSourceElement() as classic.AutomationElement)) == cmdlet.OddRootElement) { parentControlType = "Window"; } } string parentVerbosity = @"Get-Uia" + parentControlType; try { // 20140312 // if (testParent.Current.AutomationId.Length > 0) { // parentVerbosity += (" -AutomationId '" + testParent.Current.AutomationId + "'"); if (testParent.GetCurrent().AutomationId.Length > 0) { parentVerbosity += (" -AutomationId '" + testParent.GetCurrent().AutomationId + "'"); } } catch { } if (!cmdlet.NoClassInformation) { try { // 20140312 // if (testParent.Current.ClassName.Length > 0) { // parentVerbosity += (" -Class '" + testParent.Current.ClassName + "'"); if (testParent.GetCurrent().ClassName.Length > 0) { parentVerbosity += (" -Class '" + testParent.GetCurrent().ClassName + "'"); } } catch { } } try { // 20140312 // if (testParent.Current.Name.Length > 0) { // parentVerbosity += (" -Name '" + testParent.Current.Name + "'"); if (testParent.GetCurrent().Name.Length > 0) { parentVerbosity += (" -Name '" + testParent.GetCurrent().Name + "'"); } } catch { } if (cmdlet.LastRecordedItem[cmdlet.LastRecordedItem.Count - 1].ToString() == parentVerbosity) { continue; } cmdlet.LastRecordedItem.Add(parentVerbosity); cmdlet.WriteVerbose(parentVerbosity); } } } catch (Exception eErrorInTheInnerCycle) { cmdlet.WriteDebug(cmdlet, eErrorInTheInnerCycle.Message); // _errorMessageInTheInnerCycle = errorMessage = eErrorInTheInnerCycle.Message; // _errorInTheInnerCycle = true; errorOccured = true; } }
protected void GetAutomationElementsChildren(IUiElement inputObject, bool firstChild) { if (!CheckAndPrepareInput(this)) { return; } var walker = new classic.TreeWalker( classic.Condition.TrueCondition); IUiElement sibling = firstChild ? AutomationFactory.GetUiElement(walker.GetFirstChild(inputObject.GetSourceElement() as classic.AutomationElement)) : AutomationFactory.GetUiElement(walker.GetLastChild(inputObject.GetSourceElement() as classic.AutomationElement)); WriteObject(this, sibling); }
protected void GetAutomationElementsSiblings(bool nextSibling) { if (!CheckAndPrepareInput(this)) { return; } var walker = new classic.TreeWalker( classic.Condition.TrueCondition); // 20120823 // 20131109 //foreach (AutomationElement inputObject in this.InputObject) { /* foreach (IUiElement sibling in from inputObject in InputObject let sibling = null select nextSibling ? ObjectsFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement())) : ObjectsFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement()))) { //if (nextSibling) { // // 20120823 // //sibling = walker.GetNextSibling(this.InputObject); // sibling = walker.GetNextSibling(inputObject); //} else { // // 20120823 // //sibling = walker.GetPreviousSibling(this.InputObject); // sibling = walker.GetPreviousSibling(inputObject); //} // 20131113 // WriteObject(this, sibling); WriteObject(this, sibling); } */ // 20140111 // foreach (IUiElement sibling in from inputObject in InputObject let sibling = null select nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement() as AutomationElement)) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement() as AutomationElement))) // { // WriteObject(this, sibling); // } foreach (IUiElement inputObject in InputObject) { IUiElement sibling = null; // 20140102 // sibling = nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement())) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement())); sibling = nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement() as classic.AutomationElement)) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement() as classic.AutomationElement)); WriteObject(this, sibling); } // 20120823 /* foreach (IUiElement inputObject in this.InputObject) { // 20131109 //AutomationElement sibling = null; //sibling = nextSibling ? walker.GetNextSibling(inputObject) : walker.GetPreviousSibling(inputObject); IUiElement sibling = null; // 20131112 //sibling = nextSibling ? (new UiElement(walker.GetNextSibling(inputObject.SourceElement))) : (new UiElement(walker.GetPreviousSibling(inputObject.SourceElement))); sibling = nextSibling ? ObjectsFactory.GetUiElement(walker.GetNextSibling(inputObject.SourceElement)) : ObjectsFactory.GetUiElement(walker.GetPreviousSibling(inputObject.SourceElement)); //if (nextSibling) { // // 20120823 // //sibling = walker.GetNextSibling(this.InputObject); // sibling = walker.GetNextSibling(inputObject); //} else { // // 20120823 // //sibling = walker.GetPreviousSibling(this.InputObject); // sibling = walker.GetPreviousSibling(inputObject); //} WriteObject(this, sibling); } // 20120823 */ }
private List<IUiElement> GetAutomationElementsWithWalker( IUiElement element, string name, string automationId, string className, string[] controlType, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { var resultCollection = new List<IUiElement>(); var walker = new classic.TreeWalker( classic.Condition.TrueCondition); try { IUiElement oneMoreElement = AutomationFactory.GetUiElement(walker.GetFirstChild(element.GetSourceElement() as classic.AutomationElement)); resultCollection = ProcessAutomationElement( oneMoreElement, name, automationId, className, controlType, caseSensitive, onlyOneResult, onlyTopLevel); if ((onlyTopLevel || onlyOneResult) && (null != resultCollection) && resultCollection.Count > 0) { return resultCollection; } else if (null != resultCollection) { WriteObject(this, resultCollection); } while (oneMoreElement != null) { oneMoreElement = AutomationFactory.GetUiElement(walker.GetNextSibling(oneMoreElement.GetSourceElement() as classic.AutomationElement)); resultCollection = ProcessAutomationElement( oneMoreElement, name, automationId, className, controlType, caseSensitive, onlyOneResult, onlyTopLevel); if ((onlyTopLevel || onlyOneResult) && (null != resultCollection) && resultCollection.Count > 0) { return resultCollection; } else if (null != resultCollection) { WriteObject(this, resultCollection); } } } catch {} walker = null; return resultCollection; }
protected void GetAutomationElementsSiblings(bool nextSibling) { if (!CheckAndPrepareInput(this)) { return; } var walker = new classic.TreeWalker( classic.Condition.TrueCondition); // 20120823 // 20131109 //foreach (AutomationElement inputObject in this.InputObject) { /* * foreach (IUiElement sibling in from inputObject in InputObject let sibling = null select nextSibling ? ObjectsFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement())) : ObjectsFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement()))) * { * //if (nextSibling) { * // // 20120823 * // //sibling = walker.GetNextSibling(this.InputObject); * // sibling = walker.GetNextSibling(inputObject); * //} else { * // // 20120823 * // //sibling = walker.GetPreviousSibling(this.InputObject); * // sibling = walker.GetPreviousSibling(inputObject); * //} * * // 20131113 * // WriteObject(this, sibling); * WriteObject(this, sibling); * } */ // 20140111 // foreach (IUiElement sibling in from inputObject in InputObject let sibling = null select nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement() as AutomationElement)) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement() as AutomationElement))) // { // WriteObject(this, sibling); // } foreach (IUiElement inputObject in InputObject) { IUiElement sibling = null; // 20140102 // sibling = nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement())) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement())); sibling = nextSibling ? AutomationFactory.GetUiElement(walker.GetNextSibling(inputObject.GetSourceElement() as classic.AutomationElement)) : AutomationFactory.GetUiElement(walker.GetPreviousSibling(inputObject.GetSourceElement() as classic.AutomationElement)); WriteObject(this, sibling); } // 20120823 /* * foreach (IUiElement inputObject in this.InputObject) { * * // 20131109 * //AutomationElement sibling = null; * //sibling = nextSibling ? walker.GetNextSibling(inputObject) : walker.GetPreviousSibling(inputObject); * IUiElement sibling = null; * // 20131112 * //sibling = nextSibling ? (new UiElement(walker.GetNextSibling(inputObject.SourceElement))) : (new UiElement(walker.GetPreviousSibling(inputObject.SourceElement))); * sibling = nextSibling ? ObjectsFactory.GetUiElement(walker.GetNextSibling(inputObject.SourceElement)) : ObjectsFactory.GetUiElement(walker.GetPreviousSibling(inputObject.SourceElement)); * * * //if (nextSibling) { * // // 20120823 * // //sibling = walker.GetNextSibling(this.InputObject); * // sibling = walker.GetNextSibling(inputObject); * //} else { * // // 20120823 * // //sibling = walker.GetPreviousSibling(this.InputObject); * // sibling = walker.GetPreviousSibling(inputObject); * //} * * WriteObject(this, sibling); * * } // 20120823 */ }
private List <IUiElement> GetAutomationElementsWithWalker( IUiElement element, string name, string automationId, string className, string[] controlType, bool caseSensitive, bool onlyOneResult, bool onlyTopLevel) { var resultCollection = new List <IUiElement>(); var walker = new classic.TreeWalker( classic.Condition.TrueCondition); try { IUiElement oneMoreElement = AutomationFactory.GetUiElement(walker.GetFirstChild(element.GetSourceElement() as classic.AutomationElement)); resultCollection = ProcessAutomationElement( oneMoreElement, name, automationId, className, controlType, caseSensitive, onlyOneResult, onlyTopLevel); if ((onlyTopLevel || onlyOneResult) && (null != resultCollection) && resultCollection.Count > 0) { return(resultCollection); } else if (null != resultCollection) { WriteObject(this, resultCollection); } while (oneMoreElement != null) { oneMoreElement = AutomationFactory.GetUiElement(walker.GetNextSibling(oneMoreElement.GetSourceElement() as classic.AutomationElement)); resultCollection = ProcessAutomationElement( oneMoreElement, name, automationId, className, controlType, caseSensitive, onlyOneResult, onlyTopLevel); if ((onlyTopLevel || onlyOneResult) && (null != resultCollection) && resultCollection.Count > 0) { return(resultCollection); } else if (null != resultCollection) { WriteObject(this, resultCollection); } } } catch {} walker = null; return(resultCollection); }