//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { return(iid == InvokePattern.Pattern ? this : null); }
protected virtual BasePattern Pattern(AutomationPattern pattern) { return(Pattern(AutomationElement, pattern)); }
private static TPattern Get<TPattern>(AutomationElement element, AutomationPattern pattern) where TPattern : BasePattern { if (element.TryGetCurrentPattern(pattern, out var readPattern)) return (TPattern)readPattern; throw new NotSupportedException(); }
//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { return((iid == RangeValuePattern.Pattern) ? this : null); }
public PatternTypeInfo(AutomationPattern id, PatternWrapper clientSideWrapper) { this._id = id; this._clientSideWrapper = clientSideWrapper; }
public static string PatternName(AutomationPattern pattern) { Utility.ValidateArgumentNonNull(pattern, "pattern"); return(Factory.GetPatternProgrammaticName(pattern.Id)); }
public static string CleanPatternName(this AutomationPattern p) { return(p.ProgrammaticName.CleanEnd("PatternIdentifiers.Pattern")); }
/// <summary> /// Download IE file. /// </summary> /// <param name="action">Action can be Save/Save As/Open/Cancel.</param> /// <param name="path">Path where file needs to be saved (for Save As function).</param> public static void DownloadIEFile(string action, string path = "", string regexPatternToMatch = "") { Browser browser = null; if (Utility.Browser != null) // Utility.Browser is my WatiN browser instance. { if (string.IsNullOrEmpty(regexPatternToMatch)) { browser = Utility.Browser; } else { Utility.Wait(() => (browser = Browser.AttachTo <IE>(Find.ByUrl(new System.Text.RegularExpressions.Regex(regexPatternToMatch)))) != null); } } else { return; } // If doesn't work try to increase sleep interval or write your own waitUntill method Thread.Sleep(3000); // See information here (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633515(v=vs.85).aspx) Window windowMain = null; Utility.Wait(() => (windowMain = new Window(NativeMethods.GetWindow(browser.hWnd, 5))).ProcessID != 0); TreeWalker trw = new TreeWalker(Condition.TrueCondition); AutomationElement mainWindow = trw.GetParent(AutomationElement.FromHandle(browser.hWnd)); Window windowDialog = null; Utility.Wait(() => (windowDialog = new Window(NativeMethods.GetWindow(windowMain.Hwnd, 5))).ProcessID != 0); windowDialog.SetActivate(); AutomationElementCollection amc = null; Utility.Wait(() => (amc = AutomationElement.FromHandle(windowDialog.Hwnd).FindAll(TreeScope.Children, Condition.TrueCondition)).Count > 1); foreach (AutomationElement element in amc) { // You can use "Save ", "Open", ''Cancel', or "Close" to find necessary button Or write your own enum if (element.Current.Name.Equals(action)) { // If doesn't work try to increase sleep interval or write your own waitUntil method // WaitUntilButtonExsist(element,100); Thread.Sleep(1000); AutomationPattern[] pats = element.GetSupportedPatterns(); // Replace this for each if you need 'Save as' with code bellow foreach (AutomationPattern pat in pats) { // '10000' button click event id if (pat.Id == 10000) { InvokePattern click = (InvokePattern)element.GetCurrentPattern(pat); click.Invoke(); } } } else if (element.Current.Name.Equals("Save") && action == "Save As") { AutomationElementCollection bmc = element.FindAll(TreeScope.Children, Automation.ControlViewCondition); InvokePattern click1 = (InvokePattern)bmc[0].GetCurrentPattern(AutomationPattern.LookupById(10000)); click1.Invoke(); Thread.Sleep(1000); AutomationElementCollection main = mainWindow.FindAll(TreeScope.Children, Condition.TrueCondition); foreach (AutomationElement el in main) { if (el.Current.LocalizedControlType == "menu") { // First array element 'Save', second array element 'Save as', third second array element 'Save and open' InvokePattern clickMenu = (InvokePattern) el.FindAll(TreeScope.Children, Condition.TrueCondition)[1].GetCurrentPattern(AutomationPattern.LookupById(10000)); clickMenu.Invoke(); Thread.Sleep(1000); ControlSaveDialog(mainWindow, path); break; } } } } }
// Wrap pattern interface on client side, before handing to client - ie. create a client-side pattern wrapper internal static object WrapInterfaceOnClientSide(AutomationElement el, SafePatternHandle hPattern, AutomationPattern pattern) { if (hPattern.IsInvalid) { return(null); } AutomationPatternInfo pi; if (!Schema.GetPatternInfo(pattern, out pi)) { throw new ArgumentException(SR.Get(SRID.UnsupportedPattern)); } if (pi.ClientSideWrapper == null) { Debug.Assert(false, "missing client-side pattern wrapper"); return(null); } else { // false -> not cached. (Cached goes via AutomationElement.GetCachedPattern, not here) return(pi.ClientSideWrapper(el, hPattern, false)); } }
internal static object WrapObjectAsPattern(AutomationElement el, object nativePattern, AutomationPattern pattern, bool cached) { PatternTypeInfo info; if (!Schema.GetPatternInfo(pattern, out info)) { throw new ArgumentException("Unsupported pattern"); } if (info.ClientSideWrapper == null) { return(null); } return(info.ClientSideWrapper(el, nativePattern, cached)); }
public void UpdateBehavior(AutomationPattern pattern) { SetBehavior(pattern, listProvider.GetListItemBehaviorRealization(pattern, this)); }
public static T GetPattern <T>(this AutomationElement element, AutomationPattern pattern) where T : class { var patternObject = element.GetCurrentPattern(pattern); return(patternObject as T); }
private static void ClickSaveAs(AutomationElement mainWindow, AutomationElementCollection dialogElements, string filename) { foreach (AutomationElement element in dialogElements) { if (element.Current.Name.Equals("Save")) { AutomationElementCollection dialogSubElements = element.FindAll(TreeScope.Children, Automation.ControlViewCondition); InvokePattern clickPatternForSaveDropdown = (InvokePattern)dialogSubElements[0].GetCurrentPattern(AutomationPattern.LookupById(10000)); clickPatternForSaveDropdown.Invoke(); Thread.Sleep(3000); AutomationElementCollection dialogElementsInMainWindow = mainWindow.FindAll(TreeScope.Children, Condition.TrueCondition); foreach (AutomationElement currentMainWindowDialogElement in dialogElementsInMainWindow) { if (currentMainWindowDialogElement.Current.LocalizedControlType == "menu") { // first array element 'Save', second array element 'Save as', third second array element 'Save and open' InvokePattern clickMenu = (InvokePattern)currentMainWindowDialogElement.FindAll(TreeScope.Children, Condition.TrueCondition)[1].GetCurrentPattern(AutomationPattern.LookupById(10000)); clickMenu.Invoke(); Thread.Sleep(5000); ControlSaveDialog(mainWindow, filename); break; } } } } }
public RelayPatternDescriptor(AutomationPattern pattern, bool isCommon, Func <object, object> descObjFactory) : this(CleanName(pattern.ProgrammaticName), pattern.Id, isCommon, descObjFactory) { }
//------------------------------------------------------ // // Patterns Implementation // //------------------------------------------------------ #region ProxySimple Interface // Returns a pattern interface if supported. internal override object GetPatternProvider(AutomationPattern iid) { return(_item != (int)WindowsSlider.SItem.Thumb && iid == InvokePattern.Pattern ? this : null); }
public AutomationElement GetUpdatedAEWhenStructureChanged(AutomationElement mainWidow, AutomationPattern patternToCache = null, AutomationProperty propertyToCache = null) { CacheRequest cacheRequest = new CacheRequest(); cacheRequest.TreeScope = TreeScope.Element | TreeScope.Descendants | TreeScope.Children; cacheRequest.AutomationElementMode = AutomationElementMode.Full; cacheRequest.TreeFilter = System.Windows.Automation.Automation.RawViewCondition; if (patternToCache != null) { cacheRequest.Add(patternToCache); } else { cacheRequest.Add(SelectionPattern.Pattern); cacheRequest.Add(WindowPattern.Pattern); cacheRequest.Add(InvokePattern.Pattern); cacheRequest.Add(TogglePattern.Pattern); cacheRequest.Add(ExpandCollapsePattern.Pattern); cacheRequest.Add(ValuePattern.Pattern); cacheRequest.Add(SelectionItemPattern.Pattern); } if (propertyToCache != null) { cacheRequest.Add(propertyToCache); } else { cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.AutomationIdProperty); cacheRequest.Add(AutomationElement.ClassNameProperty); cacheRequest.Add(AutomationElement.ControlTypeProperty); } AutomationElement updatedElement; using (cacheRequest.Activate()) { updatedElement = mainWidow.GetUpdatedCache(cacheRequest); } return(updatedElement); }
private T GetPattern <T>(AutomationPattern pattern) where T : BasePattern { return((T)AutomationElement.GetCurrentPattern(pattern)); }