public UiEltCollection(classic.AutomationElementCollection elements) { foreach (classic.AutomationElement element in elements.Cast <classic.AutomationElement>().Where(element => null != element)) { _collectionHolder.Add(AutomationFactory.GetUiElement(element)); } }
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); }
// 20140210 internal static IExtendedModelHolder GetExtendedModelHolder(this IUiElement element, classic.TreeScope scope) // internal static IExtendedModelHolder GetExtendedModelHolder(this IUiElement element, TreeScope scope, int seconds) { // 20140210 return(AutomationFactory.GetUiExtendedModelHolder(element, scope)); // return AutomationFactory.GetUiExtendedModelHolder(element, scope, seconds); }
public override void Intercept(IInvocation invocation) { try { invocation.Proceed(); } catch (Exception eOnInvocation) { if (Preferences.Log) { // try { if (invocation.TargetType.IsSubclassOf(typeof(UiaCommand))) { AutomationFactory.GetLogHelper(string.Empty).Error(eOnInvocation.Message); // var cmdlet = // (invocation.InvocationTarget as UiaCommand).Cmdlet; // var logger = // AutomationFactory.GetLogger(); // logger.LogCmdlet(cmdlet); } // } // catch (Exception eLoggingAspect) { // // Console.WriteLine(eLoggingAspect.Message); // } } var eNewException = new Exception("Class " + invocation.TargetType.Name + ", method " + invocation.Method.Name + ": " + eOnInvocation.Message); throw eNewException; } }
public CommonCmdletBase() { #region creating the log file // 20131112 //try { // Global.CreateLogFile(); //} catch { } #endregion creating the log file CurrentData.LastCmdlet = CmdletName(this); // ?? if (!UnitTestMode && !ModuleAlreadyLoaded) { //WebDriverFactory.AutofacModule = new WebDriverModule(); //ObjectsFactory.NinjectModule = new ObjectLifecycleModule(); //WebDriverFactory.Init(); ModuleAlreadyLoaded = true; } //CurrentData.Init(); AutomationFactory.Init(); // 20140124 // runTwoScriptBlockCollections( // new ScriptBlock[] { Preferences.ModuleEcoSystem }, // null, // this, // new object[] {}); }
public static IUiElement PerformRefresh(this IUiElement element) { try { return(AutomationFactory.GetUiElement(element.GetSourceElement())); } catch (Exception) { return(null); // throw; } }
internal void FilterResultCollectionByWithControlParameter() { var filteredWindows = new List <IUiElement>(); bool exitInnerCycle; foreach (IUiElement window in ResultCollection) { if (!window.IsValid()) { continue; } var ControlSearcherData = new ControlSearcherData { InputObject = new UiElement[] { (UiElement)window } }; exitInnerCycle = false; bool addToResultCollection = false; foreach (Hashtable ht in (SearcherData as WindowSearcherData).WithControl) { ControlSearcherData.SearchCriteria = new Hashtable[] { ht }; try { var controlSearch = AutomationFactory.GetSearcherImpl <ControlSearcher>() as ControlSearcher; List <IUiElement> controlsList = controlSearch.GetElements(ControlSearcherData, 0); if (null == controlsList || 0 == controlsList.Count) { exitInnerCycle = true; addToResultCollection = false; continue; } else { addToResultCollection = true; break; } } catch (Exception) { // forcing to a next loop ResultCollection.Clear(); break; } } ControlSearcherData = null; if (addToResultCollection) { filteredWindows.Add(window); } } ResultCollection = filteredWindows; }
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); }
/// <summary> /// Processes the pipeline. /// </summary> protected override void ProcessRecord() { if (InputObject == null) { return; } var command = AutomationFactory.GetCommand <EventCommand>(this); command.Execute(); }
public HasScriptBlockCmdletBase() { TestPassed = false; Highlight = Preferences.Highlight; HighlightParent = Preferences.HighlightParent; // this.HighlightFirstChild = Preferences.HighlightFirstChild; KnownIssue = false; Banner = string.Empty; // 20140130 UiaAutomation = AutomationFactory.GetMyAutomation(); }
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 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 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 IUiElement[] GetSelection() { // 20140302 // AutomationElement[] nativeElements = (AutomationElement[])this._selectionPattern.GetParentElement().GetPatternPropertyValue(SelectionPattern.SelectionProperty, this._useCache); var nativeElements = (classic.AutomationElement[])_selectionPattern.GetParentElement().GetPatternPropertyValue(classic.SelectionPattern.SelectionProperty, _useCache); IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements); if (null == tempCollection || 0 == tempCollection.Count) { return(new UiElement[] {}); } else { return(tempCollection.Cast <IUiElement>().ToArray <IUiElement>()); } }
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); }
public IUiElement[] GetColumnHeaderItems() { // return (AutomationElement[])this._el.GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache); // 20140302 // AutomationElement[] nativeElements = (AutomationElement[])this._tableItemPattern.GetParentElement().GetPatternPropertyValue(TableItemPattern.ColumnHeaderItemsProperty, this._useCache); var nativeElements = (classic.AutomationElement[])_tableItemPattern.GetParentElement().GetPatternPropertyValue(classic.TableItemPattern.ColumnHeaderItemsProperty, _useCache); IUiEltCollection tempCollection = AutomationFactory.GetUiEltCollection(nativeElements); if (null == tempCollection || 0 == tempCollection.Count) { return(new UiElement[] {}); } else { return(tempCollection.Cast <IUiElement>().ToArray()); } }
internal static IUiElement InvokeContextMenu(this IUiElement inputObject, HasControlInputCmdletBase cmdlet, int x, int y) { IUiElement resultElement = null; try { if (!cmdlet.ClickControl( cmdlet, inputObject, new ClickSettings() { RightClick = true, RelativeX = (x < 0 ? Preferences.ClickOnControlByCoordX : x), RelativeY = (y < 0 ? Preferences.ClickOnControlByCoordY : y) })) { } } catch (Exception) { throw new Exception("failed to click on the control"); } // 20140116 // what are these x and y? // int x = Cursor.Position.X; // int y = Cursor.Position.Y; var contextMenuSearcher = AutomationFactory.GetSearcherImpl <ContextMenuSearcher>(); var contextMenuSearcherData = new ContextMenuSearcherData { InputObject = inputObject, ProcessId = inputObject.GetCurrent().ProcessId }; var elementsMenuRoot = contextMenuSearcher.GetElements( contextMenuSearcherData, Preferences.Timeout); resultElement = elementsMenuRoot.First(element => null != element); return(resultElement); }
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); } }
internal static IUiEltCollection PerformFindAll(this IExtendedModelHolder holder, classic.ControlType controlType) { try { var controlSearcherData = new ControlSearcherData { ControlType = controlType.ConvertControlTypeToStringArray(), InputObject = new IUiElement[] { holder.GetParentElement() } }; var controlSearcher = AutomationFactory.GetSearcherImpl <ControlSearcher>(); return(AutomationFactory.GetUiEltCollection( controlSearcher.GetElements( controlSearcherData, holder.Seconds))); } catch (Exception) { return(new UiEltCollection(true)); } }
public override void Intercept(IInvocation invocation) { if (Preferences.Log) { try { if (invocation.TargetType.IsSubclassOf(typeof(UiaCommand))) { var cmdlet = (invocation.InvocationTarget as UiaCommand).Cmdlet; var logger = AutomationFactory.GetLogHelper(string.Empty); logger.LogCmdlet(cmdlet); } } catch (Exception) { // Console.WriteLine(eLoggingAspect.Message); } } invocation.Proceed(); }
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"); } }
public virtual TPatternInterface GetCurrentPattern <TPatternInterface>(classic.AutomationPattern pattern) where TPatternInterface : IBasePattern { switch (_innerElementType) { case InnerElementTypes.AutomationElementNet: if (Preferences.FromCache) { return((TPatternInterface)AutomationFactory.GetPatternAdapter <TPatternInterface>(this, _elementHolderNet.GetCachedPattern(pattern))); } else { return((TPatternInterface)AutomationFactory.GetPatternAdapter <TPatternInterface>(this, _elementHolderNet.GetCurrentPattern(pattern))); } // default: // case InnerElementTypes.AutomationElementCom: // // // 20131208 case InnerElementTypes.UiElement: // return Preferences.FromCache ? _elementHolderAdapter.GetCachedPattern(pattern) : _elementHolderAdapter.GetCurrentPattern(pattern); return(Preferences.FromCache ? default(TPatternInterface) : _elementHolderAdapter.GetCurrentPattern <TPatternInterface>(pattern)); // default: // return Preferences.FromCache ? _elementHolderNet.GetCachedPattern(pattern) : _elementHolderNet.GetCurrentPattern(pattern); default: if (Preferences.FromCache) { return((TPatternInterface)AutomationFactory.GetPatternAdapter <TPatternInterface>(this, _elementHolderNet.GetCachedPattern(pattern))); } else { return((TPatternInterface)AutomationFactory.GetPatternAdapter <TPatternInterface>(this, _elementHolderNet.GetCurrentPattern(pattern))); } } // return default(N); }
public virtual IUiEltCollection this[string infoString] { get { if (string.IsNullOrEmpty(infoString)) { return(null); } try { if (null == this || 0 == Count) { return(null); } const WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled; var wildcardInfoString = new WildcardPattern(infoString, options); var queryByStringData = from collectionItem in _collectionHolder //.ToArray() where wildcardInfoString.IsMatch(collectionItem.GetCurrent().Name) || wildcardInfoString.IsMatch(collectionItem.GetCurrent().AutomationId) || wildcardInfoString.IsMatch(collectionItem.GetCurrent().ClassName) select collectionItem; return(AutomationFactory.GetUiEltCollection(queryByStringData)); } catch { return(null); // return new IUiElement[] {}; } } }
internal static T GetHolder <T>(this IUiElement element) { return(AutomationFactory.GetHolder <T>(element)); }
static ExtensionMethodsElementExtended() { InputSimulator = AutomationFactory.GetInputSimulator(); }