protected internal IUiElement GetActiveWindow() { IUiElement result = null; try { IntPtr hWnd = NativeMethods.GetForegroundWindow(); if (hWnd == IntPtr.Zero) { return(result); } result = AutomationFactory.GetUiElement(classic.AutomationElement.FromHandle(hWnd)); WriteVerbose( this, "the active window element is " + // 20140312 // result.Current.Name); result.GetCurrent().Name); } catch (Exception e) { WriteVerbose(this, e.Message); } return(result); }
public UiEltCollection(classic.AutomationElementCollection elements) { foreach (classic.AutomationElement element in elements.Cast <classic.AutomationElement>().Where(element => null != element)) { _collectionHolder.Add(AutomationFactory.GetUiElement(element)); } }
public static IUiElement PerformRefresh(this IUiElement element) { try { return(AutomationFactory.GetUiElement(element.GetSourceElement())); } catch (Exception) { return(null); // throw; } }
public UiEltCollection(IEnumerable elements) { foreach (var element in elements.Cast <object>().Where(element => null != element && element is classic.AutomationElement)) { _collectionHolder.Add(AutomationFactory.GetUiElement(element as classic.AutomationElement)); } foreach (var element in elements.Cast <object>().Where(element => null != element && element is IUiElement)) { _collectionHolder.Add((IUiElement)element); } }
public static IUiElement GetContainingGridTableItemPattern(this IUiElement element) { try { // 20140102 // return AutomationFactory.GetUiElement(element.GetCurrentPattern<ITableItemPattern>(classic.TableItemPattern.Pattern).Current.ContainingGrid.GetSourceElement()); return(AutomationFactory.GetUiElement(element.GetCurrentPattern <ITableItemPattern>(classic.TableItemPattern.Pattern).Current.ContainingGrid.GetSourceElement() as classic.AutomationElement)); } catch (Exception) { // // throw; } return(null); }
public static IUiElement PerformNavigateToPreviousSibling(this IUiElement element) { IUiElement result = null; var walker = new classic.TreeWalker(classic.Condition.TrueCondition); try { result = AutomationFactory.GetUiElement(walker.GetPreviousSibling(element.GetSourceElement() as classic.AutomationElement)); } catch { } return(result); }
/// <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()); } }
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); }
public static IUiElement FromHandle(IntPtr controlHandle) { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: return(AutomationFactory.GetUiElement(classic.AutomationElement.FromHandle(controlHandle))); // case InnerElementTypes.AutomationElementCom: // // case InnerElementTypes.UiElement: return(FromHandle(controlHandle)); default: return(AutomationFactory.GetUiElement(classic.AutomationElement.FromHandle(controlHandle))); } }
public static IUiElement FromPoint(Point pt) { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: return(AutomationFactory.GetUiElement(classic.AutomationElement.FromPoint(pt))); // case InnerElementTypes.AutomationElementCom: // // case InnerElementTypes.UiElement: return(FromPoint(pt)); default: return(AutomationFactory.GetUiElement(classic.AutomationElement.FromPoint(pt))); } }
public virtual IUiElement FindFirst(classic.TreeScope scope, UIANET.System.Windows.Automation.Condition condition) { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: return(AutomationFactory.GetUiElement(_elementHolderNet.FindFirst(scope, condition))); // case InnerElementTypes.AutomationElementCom: // // case InnerElementTypes.UiElement: return(_elementHolderAdapter.FindFirst(scope, condition)); default: return(AutomationFactory.GetUiElement(_elementHolderNet.FindFirst(scope, condition))); } }
public static IUiElement PerformGetItem(this IUiElement element, int row, int column) { try { // return element.GetCurrentPattern<IGridPattern>(classic.GridPattern.Pattern).GetItem(row, column); return(AutomationFactory.GetUiElement(element.GetCurrentPattern <IGridPattern>(classic.GridPattern.Pattern).GetItem(row, column).GetSourceElement())); // 20140102 // IUiElement eltInExtMethod = AutomationFactory.GetUiElement(element.GetCurrentPattern<IGridPattern>(classic.GridPattern.Pattern).GetItem(row, column).GetSourceElement()); // IUiElement eltInExtMethod = AutomationFactory.GetUiElement(element.GetCurrentPattern<IGridPattern>(classic.GridPattern.Pattern).GetItem(row, column).GetSourceElement()); // as AutomationElement); // return eltInExtMethod; } catch (Exception) { // // throw; } return(null); }
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); } }
protected override void SaveEventInput( // 20131109 classic.AutomationElement src, //IUiElement src, classic.AutomationEventArgs e, string programmaticName, bool infoAdded) { // inform the Wait-UiaEventRaised cmdlet try { // 20131109 //CurrentData.LastEventSource = src; //.SourceElement; // as AutomationElement; // 20131112 //CurrentData.LastEventSource = new UiElement(src); CurrentData.LastEventSource = AutomationFactory.GetUiElement(src); CurrentData.LastEventArgs = e; // as AutomationEventArgs; CurrentData.LastEventType = programmaticName; CurrentData.LastEventInfoAdded = infoAdded; } catch { //WriteVerbose(this, "failed to register an event in the collection"); } }
// internal UiaGridPattern(AutomationElement el, SafePatternHandle hPattern, bool cached) : base(el, hPattern) // { // this._hPattern = hPattern; // this._cached = cached; // } public virtual IUiElement GetItem(int row, int column) { // SafeNodeHandle hnode = UiaCoreApi.GridPattern_GetItem(this._hPattern, row, column); // return AutomationElement.Wrap(hnode); return(AutomationFactory.GetUiElement(_gridPattern.GetItem(row, column))); }
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 */ }
/// <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; } }
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); }