public static AutomationElement GetStartButton() { AndCondition cond = new AndCondition( new PropertyCondition(AutomationElement.AccessKeyProperty, "Ctrl+Esc"), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)); return AutomationElement.RootElement.FindFirst(TreeScope.Subtree, cond); }
private bool DismissUACPrompts() { logger.Info("Trying to find the (focused) UAC elevation prompt."); AutomationElement dialog = this.uiAutomation.GetFocusedWindowOrRoot(); { var conditions = new AndCondition( Automation.ContentViewCondition, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition(AutomationElement.ClassNameProperty, "CtrlNotifySink")); var elements = dialog.FindAll(TreeScope.Descendants, conditions); if (elements.Count > 0) { logger.Info("The UAC elevation prompt found."); // sending keystrokes (Alt + Y / N) is more reliable. this.keyboard.ReleaseAllModifierKeys(); this.keyboard.KeyUpOrDown(Key.LeftAlt); this.keyboard.KeyPress(this.allowed ? Key.Y : Key.N); this.keyboard.KeyUpOrDown(Key.LeftAlt); return true; } } return false; }
public void ControlViewConditionTest() { SWA.Condition controlViewCond = SWA.Automation.ControlViewCondition; Assert.IsNotNull(controlViewCond, "ControlViewCondition"); SWA.PropertyCondition controlViewPropCond = controlViewCond as SWA.PropertyCondition; Assert.IsNull(controlViewPropCond, "ControlViewCondition is not a PropertyCondition"); SWA.AndCondition controlViewAndCond = controlViewCond as SWA.AndCondition; Assert.IsNull(controlViewAndCond, "ControlViewCondition is not a AndCondition"); SWA.OrCondition controlViewOrCond = controlViewCond as SWA.OrCondition; Assert.IsNull(controlViewOrCond, "ControlViewCondition is not a OrCondition"); SWA.NotCondition controlViewNotCond = controlViewCond as SWA.NotCondition; Assert.IsNotNull(controlViewNotCond, "ControlViewCondition is a NotCondition"); SWA.Condition subCond = controlViewNotCond.Condition; Assert.IsNotNull(subCond, "ControlViewCondition.Condition"); SWA.PropertyCondition subPropertyCond = subCond as SWA.PropertyCondition; Assert.IsNotNull(subPropertyCond, "ControlViewCondition.Condition is a PropertyCondition"); Assert.AreEqual(AEIds.IsControlElementProperty, subPropertyCond.Property, "ControlViewCondition.Condition.Property"); Assert.AreEqual(false, subPropertyCond.Value, "ControlViewCondition.Condition.Value"); Assert.AreEqual(SWA.PropertyConditionFlags.None, subPropertyCond.Flags, "ControlViewCondition.Condition.Flags"); }
public Window FindWindow(Condition condition, TimeSpan timeout, FailureToFindHandler handler) { var allConditions = condition; if (_process != null) { allConditions = new AndCondition(condition, new PropertyCondition(AutomationElement.ProcessIdProperty, _process.Id)); } return new WindowFinder().FindWindow(allConditions, timeout, handler); }
public Window GetWindow (string name) { AndCondition cond = new AndCondition ( new PropertyCondition (AutomationElementIdentifiers.ControlTypeProperty, ControlType.Window), new PropertyCondition (AutomationElementIdentifiers.NameProperty, name)); var ae = AutomationElement.RootElement.FindFirst (TreeScope.Children, cond); return new Window (ae); }
public void ShouldDescribeCompoundConditionsUsingAnd() { var nameCondition = new PropertyCondition(AutomationElement.NameProperty, "Wobble"); var controlTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window); var condition = new AndCondition(nameCondition, controlTypeCondition); var expected = "(Name='Wobble' and ControlType='" + ControlType.Window.Id + "')"; Assert.AreEqual(expected, new ConditionDescriber().Describe(condition)); }
public static AutomationElement FindElementById(AutomationElement parentElement, string automationID, ControlType type) { PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type); PropertyCondition IDCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID); AndCondition andCondition = new AndCondition(typeCondition, IDCondition); return parentElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition); }
public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type) { PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type); PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className); AndCondition andCondition = new AndCondition(typeCondition, IDCondition); return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition); }
public static AutomationElement FindWindowByName(AutomationElement rootElement, string name, ControlType type) { PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, name); PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type); AndCondition andCondition = new AndCondition(nameCondition, typeCondition); return rootElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition); }
public override void ExitAndCondition(PrevailParser.AndConditionContext context) { base.ExitAndCondition(context); var right = _conditionStack.Pop(); var left = _conditionStack.Pop(); var and = new AndCondition(new Condition[] { left, right }); _conditionStack.Push(and); }
public Window FindGtkSubWindow (Window mainWindow, string name) { AndCondition cond = new AndCondition ( new PropertyCondition (AutomationElementIdentifiers.ProcessIdProperty, mainWindow.AutomationElement.Current.ProcessId), new PropertyCondition (AutomationElementIdentifiers.ControlTypeProperty, ControlType.Window), new PropertyCondition (AutomationElementIdentifiers.NameProperty, name)); var ae = AutomationElement.RootElement.FindFirst (TreeScope.Children, cond); return new Window (ae); }
public InternalTreeWalker() { // TreeWalker instance as a global variable started consuming more // memory over a period of time, moving the code to individual methods // kept the memory usage low // Ignore Ldtpd from list of applications Condition condition1 = new PropertyCondition(AutomationElement.ProcessIdProperty, Process.GetCurrentProcess().Id); Condition condition2 = new AndCondition(new Condition[] { System.Windows.Automation.Automation.ControlViewCondition, new NotCondition(condition1)}); walker = new TreeWalker(condition2); }
public void ContentViewConditionTest() { SWA.Condition contentViewCond = SWA.Automation.ContentViewCondition; Assert.IsNotNull(contentViewCond, "ContentViewCondition"); SWA.PropertyCondition contentViewPropCond = contentViewCond as SWA.PropertyCondition; Assert.IsNull(contentViewPropCond, "ContentViewCondition is not a PropertyCondition"); SWA.AndCondition contentViewAndCond = contentViewCond as SWA.AndCondition; Assert.IsNull(contentViewPropCond, "ContentViewCondition is not a PropertyCondition"); Assert.IsNull(contentViewAndCond, "ContentViewCondition is not a AndCondition"); SWA.OrCondition contentViewOrCond = contentViewCond as SWA.OrCondition; Assert.IsNull(contentViewOrCond, "ContentViewCondition is not a OrCondition"); SWA.NotCondition contentViewNotCond = contentViewCond as SWA.NotCondition; Assert.IsNotNull(contentViewNotCond, "ContentViewCondition is a NotCondition"); SWA.Condition subCond = contentViewNotCond.Condition; Assert.IsNotNull(subCond, "ContentViewCondition.Condition"); SWA.OrCondition subOrCond = subCond as SWA.OrCondition; Assert.IsNotNull(subOrCond, "ContentViewCondition.Condition is a OrCondition"); SWA.Condition [] subSubConditions = subOrCond.GetConditions(); Assert.AreEqual(2, subSubConditions.Length, "ContentViewCondition.Condition.GetConditions length"); SWA.PropertyCondition subSubPropertyCond1 = subSubConditions [0] as SWA.PropertyCondition; Assert.IsNotNull(subSubPropertyCond1); SWA.PropertyCondition subSubPropertyCond2 = subSubConditions [1] as SWA.PropertyCondition; Assert.IsNotNull(subSubPropertyCond2); Assert.AreEqual(AEIds.IsControlElementProperty, subSubPropertyCond1.Property, "subcondition1 Property"); Assert.AreEqual(false, subSubPropertyCond1.Value, "subcondition1 Value"); Assert.AreEqual(SWA.PropertyConditionFlags.None, subSubPropertyCond1.Flags, "subcondition1 Flags"); Assert.AreEqual(AEIds.IsContentElementProperty.ProgrammaticName, subSubPropertyCond2.Property.ProgrammaticName, "subcondition2 Property"); Assert.AreEqual(false, subSubPropertyCond2.Value, "subcondition2 Value"); Assert.AreEqual(SWA.PropertyConditionFlags.None, subSubPropertyCond2.Flags, "subcondition2 Flags"); }
private static void getOutlookWindow(ref AutomationElement mainWnd) { //Create a property condition with the element's type PropertyCondition typeCondition = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Window ); //Create a property condition with the element's name PropertyCondition nameCondition = new PropertyCondition( AutomationElement.NameProperty, "Inbox - " + email + " - Outlook" ); //Create the conjunction condition AndCondition andCondition = new AndCondition( typeCondition, nameCondition ); //Ask the Desktop to find the element within its children with the given condition mainWnd = AutomationElement.RootElement.FindFirst( TreeScope.Children, andCondition ); while ( mainWnd == null ) { mainWnd = AutomationElement.RootElement.FindFirst( TreeScope.Children, andCondition ); } }
public void RawViewConditionTest() { SWA.Condition rawViewCond = SWA.Automation.RawViewCondition; Assert.IsNotNull(rawViewCond, "RawViewCondition"); SWA.PropertyCondition rawViewPropCond = rawViewCond as SWA.PropertyCondition; Assert.IsNull(rawViewPropCond, "RawViewCondition is not a PropertyCondition"); SWA.AndCondition rawViewAndCond = rawViewCond as SWA.AndCondition; Assert.IsNull(rawViewAndCond, "RawViewCondition is not a AndCondition"); SWA.OrCondition rawViewOrCond = rawViewCond as SWA.OrCondition; Assert.IsNull(rawViewOrCond, "RawViewCondition is not a OrCondition"); SWA.NotCondition rawViewNotCond = rawViewCond as SWA.NotCondition; Assert.IsNull(rawViewNotCond, "RawViewCondition is not a NotCondition"); }
private Condition GetPropertyConditions() { Condition properties = null; if (searchProperties.Count > 1) { var propertyList = new List<Condition>(); foreach (var property in searchProperties) { propertyList.Add(new PropertyCondition(property.PropertyName, property.PropertyValue)); } properties = new AndCondition(propertyList.ToArray()); } else { properties = new PropertyCondition(searchProperties[0].PropertyName, searchProperties[0].PropertyValue); } return properties; }
public int Find(int parent, int id, int index) { AutomationElement baseElement = base.Find(parent); Condition[] conditions = { new PropertyCondition(AutomationElement.ControlTypeProperty, controlType), new PropertyCondition(AutomationElement.RuntimeIdProperty,id) }; Condition locator = new AndCondition(conditions); AutomationElementCollection elements = baseElement.FindAll(TreeScope.Subtree, locator); if (elements.Count <= index) { return 0; } logger.Debug(String.Format("Found hwnd: {0}", elements[index].Current.NativeWindowHandle)); return elements[index].Current.NativeWindowHandle; }
public bool IswindowExists() { AutomationElement win = null; // while (win == null ) // { AutomationElement ae = AutomationElement.RootElement; Condition cond1 = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "LOWIS: Connect")); win = ae.FindFirst(TreeScope.Descendants, cond1); if (win == null) { return false; } else { return true; } }
public void VerifyBasicConditions() { // Class = 'Awsum' Condition result1 = new PropertyCondition(AutomationElement.ClassNameProperty, "Awsum"); var expression = new ExpressionLocator("", 1, Scope.Descendants, "Class = 'Awsum'"); var result1Expression = expression.Condition; Assert.IsTrue(AutomationHelper.Compare(result1, result1Expression)); // Class != 'Awsum' Condition result2 = new NotCondition( new PropertyCondition(AutomationElement.ClassNameProperty, "Awsum")); var expression2 = new ExpressionLocator("", 1, Scope.Descendants, "Class != 'Awsum'"); var result2Expression = expression2.Condition; Assert.IsTrue(AutomationHelper.Compare(result2, result2Expression)); // Class = 'Awsum' And Name = 'Adi' Condition result3 = new AndCondition( new PropertyCondition(AutomationElement.ClassNameProperty, "Awsum"), new PropertyCondition(AutomationElement.NameProperty, "Adi")); var expression3 = new ExpressionLocator("", 1, Scope.Descendants, "Class = 'Awsum' And Name = 'Adi'"); var result3Expression = expression3.Condition; Assert.IsTrue(AutomationHelper.Compare(result3, result3Expression)); // Test }
public void AndConditionTest() { // Positive test Condition condition = Condition.TrueCondition; Condition condition2 = Condition.FalseCondition; AndCondition target = new AndCondition(condition, condition2); Condition[] actual; actual = target.GetConditions(); Assert.IsNotNull(actual); Assert.AreEqual(actual.Length, 2); // Negative test - include a null try { target = new AndCondition(condition, null); Assert.Fail("expected exception"); } catch (System.ArgumentException) { } }
public Condition[] GetConditions() { if (!(IUIAutomationCondition is IUIAutomationAndCondition automationCondition)) { return(null); } var typedArray = automationCondition.GetChildren().ToTypedArray <IUIAutomationCondition>(); var conditionArray = new Condition[typedArray.Length]; for (var index = 0; index < conditionArray.Length; ++index) { if (typedArray[index] is IUIAutomationPropertyCondition) { var propertyCondition = typedArray[index] as IUIAutomationPropertyCondition; conditionArray[index] = new PropertyCondition(property: AutomationProperty.LookupById(id: propertyCondition.propertyId), value: propertyCondition.PropertyValue); } else if (typedArray[index] is IUIAutomationAndCondition) { var automationAndCondition = typedArray[index] as IUIAutomationAndCondition; conditionArray[index] = new AndCondition(iUIAConditions: automationAndCondition.GetChildren().ToTypedArray <IUIAutomationCondition>()); } else if (typedArray[index] is IUIAutomationOrCondition) { var automationOrCondition = typedArray[index] as IUIAutomationOrCondition; conditionArray[index] = new OrCondition(iUIAConditions: automationOrCondition.GetChildren().ToTypedArray <IUIAutomationCondition>()); } else if (typedArray[index] is IUIAutomationNotCondition) { conditionArray[index] = new NotCondition(condition: new Condition(condition: typedArray[index])); } else if (typedArray[index] != null) { conditionArray[index] = new Condition(condition: typedArray[index]); } } return(conditionArray); }
//public void Start() //{ // if (PopupOccured != null) // { // PopupOccured(this, e); // } //} public void closepopup() { AutomationElement ae = AutomationElement.RootElement; Condition cond1 = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "LOWIS: Connect")); AutomationElement win = ae.FindFirst(TreeScope.Descendants, cond1); if (win != null) // perform the action when window is found { Console.WriteLine(" Hearing to Event fired I Got Window ...... "); Condition cond2 = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Close")); AutomationElement btn = win.FindFirst(TreeScope.Descendants, cond2); InvokePattern ivk = (InvokePattern)btn.GetCurrentPattern(InvokePattern.Pattern); ivk.Invoke(); } else { Console.WriteLine(" Hearing to Event fired I did not get a Window ...... "); return; } }
public override WidgetPrx[] getWindows(Ice.Current current__) { // Check based on pid and for ControlType.Window PropertyCondition pidCondition = new PropertyCondition( AutomationElement.ProcessIdProperty, process.Id); PropertyCondition windowCondition = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Window); Condition condition = new AndCondition(pidCondition, windowCondition); // Check the children of the automation root for windows AutomationElement root = AutomationElement.RootElement; AutomationElementCollection rootWindows = root.FindAll(TreeScope.Children, condition); // Register the windows WidgetPrx[] windows = new WidgetPrx[rootWindows.Count]; for (int i = 0; i < rootWindows.Count; i++) { windows[i] = new WidgetI(this, rootWindows[i]).Proxy; } return windows; }
/// ------------------------------------------------------------------- /// <summary></summary> /// ------------------------------------------------------------------- internal void TS_GetRandomSelectableItem(AutomationElement selectionContainer, out AutomationElement element, bool selectedState, CheckType checkType) { Comment("Calling LibraryGetSelectionItems()"); element = null; AutomationElement element2 = null; ; AutomationElementCollection IsSelected; if (selectionContainer.Current.ControlType == ControlType.Calendar) { IsSelected = selectionContainer.FindAll(TreeScope.Descendants, new PropertyCondition(SelectionItemPattern.IsSelectedProperty, true)); if (IsSelected.Count > 0) { switch (selectedState) { case true: // Find something that is selected { // Return the 1st or last element since you can only remove exterior elements from selection element = IsSelected[(bool)Helpers.RandomValue(true, true) == true ? 0 : IsSelected.Count - 1]; break; } case false: // Find something that is not selected yet { switch ((bool)Helpers.RandomValue(true, true)) { case true: // Looking for something at the beginning of the selection element2 = TreeWalker.RawViewWalker.GetPreviousSibling(IsSelected[0]); // If we are at the start, get something from the tail if (element2 == null) { element2 = TreeWalker.RawViewWalker.GetNextSibling(IsSelected[IsSelected.Count - 1]); } // If for some reason they are all selected, then error out if (element2 == null) ThrowMe(checkType, "Could not get any element that was unselected"); break; case false: // Looking for something at the end of the selection element2 = TreeWalker.RawViewWalker.GetNextSibling(IsSelected[IsSelected.Count - 1]); // If we are at the end, get something from the start if (element2 == null) { element2 = TreeWalker.RawViewWalker.GetPreviousSibling(IsSelected[0]); } // If for some reason they are all selected, then error out if (element2 == null) ThrowMe(checkType, "Could not get any element that was unselected"); break; } element = element2; break; } } } } else { Condition condition = new AndCondition ( new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true), new PropertyCondition(SelectionItemPattern.IsSelectedProperty, selectedState) ); IsSelected = selectionContainer.FindAll(TreeScope.Descendants, condition); if (IsSelected.Count > 0) { // Return any element element = IsSelected[(int)Helpers.RandomValue(0, IsSelected.Count - 1)]; } } if (element == null) ThrowMe(checkType, "Could not find element who's SelectionItemPattern.IsSelected = " + selectedState); Comment("Found AutomationElement(" + Library.GetUISpyLook(element) + ")"); m_TestStep++; }
public Window [] FindAllGtkSubWindow (Window mainWindow, string name) { List<Window> retval = new List<Window> (); AndCondition cond = new AndCondition ( new PropertyCondition (AutomationElementIdentifiers.ProcessIdProperty, mainWindow.AutomationElement.Current.ProcessId), new PropertyCondition (AutomationElementIdentifiers.ControlTypeProperty, ControlType.Window), new PropertyCondition (AutomationElementIdentifiers.NameProperty, name)); var elements = AutomationElement.RootElement.FindAll (TreeScope.Children, cond); foreach (AutomationElement ae in elements) { retval.Add (new Window (ae)); } return retval.ToArray(); }
private Condition MergeMultiConditions(Dictionary<AutomationProperty, object> searchCriteria) { Condition condition; if (1 == searchCriteria.Count) { condition = new PropertyCondition(searchCriteria.Keys.First() as AutomationProperty, searchCriteria.Values.First() as object); } else { List<Condition> listCondition = new List<Condition>(); foreach (KeyValuePair<AutomationProperty, object> item in searchCriteria) { listCondition.Add(new PropertyCondition(item.Key, item.Value)); } condition = new AndCondition(listCondition.ToArray()); } return condition; }
/// -------------------------------------------------------------------- /// <summary> /// Finds the text control in our target. /// </summary> /// <param name="src">The object that raised the event.</param> /// <param name="e">Event arguments.</param> /// <remarks> /// Initializes the TextPattern object and event handlers. /// </remarks> /// -------------------------------------------------------------------- private void FindTextProvider_Click(object src, RoutedEventArgs e) { // Set up the conditions for finding the text control. var documentControl = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Document); var textPatternAvailable = new PropertyCondition( AutomationElement.IsTextPatternAvailableProperty, true); var findControl = new AndCondition(documentControl, textPatternAvailable); // Get the Automation Element for the first text control found. // For the purposes of this sample it is sufficient to find the // first text control. In other cases there may be multiple text // controls to sort through. _targetDocument = _targetWindow.FindFirst(TreeScope.Descendants, findControl); // Didn't find a text control. if (_targetDocument == null) { _targetResult.Content = _wpfTarget + " does not contain a Document control type."; _targetResult.Background = Brushes.Salmon; _startWpfTargetButton.IsEnabled = false; return; } // Get required control patterns _targetTextPattern = _targetDocument.GetCurrentPattern( TextPattern.Pattern) as TextPattern; // Didn't find a text control that supports TextPattern. if (_targetTextPattern == null) { _targetResult.Content = _wpfTarget + " does not contain an element that supports TextPattern."; _targetResult.Background = Brushes.Salmon; _startWpfTargetButton.IsEnabled = false; return; } // Text control is available so display the client controls. _infoGrid.Visibility = Visibility.Visible; _targetResult.Content = "Text provider found."; _targetResult.Background = Brushes.LightGreen; // Initialize the document range for the text of the document. _documentRange = _targetTextPattern.DocumentRange; // Initialize the client's search buttons. if (_targetTextPattern.DocumentRange.GetText(1).Length > 0) { _searchForwardButton.IsEnabled = true; } // Initialize the client's search TextBox. _searchString.IsEnabled = true; // Check if the text control supports text selection if (_targetTextPattern.SupportedTextSelection == SupportedTextSelection.None) { _targetResult.Content = "Unable to select text."; _targetResult.Background = Brushes.Salmon; return; } // Edit control found so remove the find button from the client. _findEditButton.Visibility = Visibility.Collapsed; // Initialize the client with the current target selection, if any. NotifySelectionChanged(); // Search starts at beginning of doc and goes forward _searchBackward = false; // Initialize a text changed listener. // An instance of TextPatternRange will become invalid if // one of the following occurs: // 1) The text in the provider changes via some user activity. // 2) ValuePattern.SetValue is used to programatically change // the value of the text in the provider. // The only way the client application can detect if the text // has changed (to ensure that the ranges are still valid), // is by setting a listener for the TextChanged event of // the TextPattern. If this event is raised, the client needs // to update the targetDocumentRange member data to ensure the // user is working with the updated text. // Clients must always anticipate the possibility that the text // can change underneath them. Automation.AddAutomationEventHandler( TextPattern.TextChangedEvent, _targetDocument, TreeScope.Element, TextChanged); // Initialize a selection changed listener. // The target selection is reflected in the client. Automation.AddAutomationEventHandler( TextPattern.TextSelectionChangedEvent, _targetDocument, TreeScope.Element, OnTextSelectionChange); }
public object getControlConditions(GetCmdletBase cmdlet1, string controlType, bool caseSensitive, bool AndVsOr) { System.Windows.Automation.ControlType ctrlType = null; System.Windows.Automation.AndCondition andConditions = null; // 20130128 System.Windows.Automation.OrCondition orConditions = null; System.Windows.Automation.PropertyCondition condition = null; // 20130128 System.Windows.Automation.AndCondition allConditions = null; // 20130128 object conditionsToReturn = null; // 20130127 PropertyConditionFlags flags = PropertyConditionFlags.None; if (!caseSensitive) { flags = PropertyConditionFlags.IgnoreCase; } GetControlCmdletBase cmdlet = // 20130220 (GetControlCmdletBase)cmdlet1; //new GetControlCmdletBase(); // 20130128 // the TextSearch mode // 20130220 //if (null != cmdlet.ContainsText && if (null != (cmdlet as GetControlCmdletBase) && null != cmdlet.ContainsText && // 20130220 string.Empty != cmdlet.ContainsText && !AndVsOr) { // 20130220 cmdlet.Name = //cmdlet.AutomationId = (cmdlet as GetControlCmdletBase).AutomationId = //cmdlet.Class = (cmdlet as GetControlCmdletBase).Class = //cmdlet.Value = (cmdlet as GetControlCmdletBase).Value = //cmdlet.ContainsText; (cmdlet as GetControlCmdletBase).ContainsText; } //if (cmdlet.ControlType != null && cmdlet.ControlType.Length > 0) { if (controlType != null && controlType.Length > 0) { WriteVerbose(this, "getting control with control type = " + controlType); ctrlType = UIAHelper.GetControlTypeByTypeName(controlType); WriteVerbose(cmdlet, "ctrlType = " + ctrlType.ProgrammaticName); } System.Windows.Automation.PropertyCondition ctrlTypeCondition = null, classCondition = null, titleCondition = null, autoIdCondition = null; // 20130127 System.Windows.Automation.PropertyCondition valueCondition = null; //WriteVerbose(cmdlet, "ctrlType = " + ctrlType.ProgrammaticName); int conditionsCounter = 0; if (ctrlType != null) { ctrlTypeCondition = new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ControlTypeProperty, ctrlType); //, // // 20130127 // flags); WriteVerbose(cmdlet, "ControlTypeProperty '" + ctrlType.ProgrammaticName + "' is used"); // 20130128 //conditionsCounter++; } // 20120828 if (cmdlet.Class != null && cmdlet.Class != "") //if (null != cmdlet.Class && cmdlet.Class.Length > 0) { { classCondition = new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ClassNameProperty, cmdlet.Class, // 20130121 //PropertyConditionFlags.IgnoreCase); // 20130127 flags); WriteVerbose(cmdlet, "ClassNameProperty '" + cmdlet.Class + "' is used"); conditionsCounter++; } if (cmdlet.AutomationId != null && cmdlet.AutomationId != "") { autoIdCondition = new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.AutomationIdProperty, cmdlet.AutomationId, // 20130121 //PropertyConditionFlags.IgnoreCase); // 20130127 flags); WriteVerbose(cmdlet, "AutomationIdProperty '" + cmdlet.AutomationId + "' is used"); conditionsCounter++; } if (cmdlet.Name != null && cmdlet.Name != "") // allow empty name { titleCondition = new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.NameProperty, cmdlet.Name, // 20130121 //PropertyConditionFlags.IgnoreCase); // 20130127 flags); WriteVerbose(cmdlet, "NameProperty '" + cmdlet.Name + "' is used"); conditionsCounter++; } // 20130127 if (cmdlet.Value != null && cmdlet.Value != "") { valueCondition = new System.Windows.Automation.PropertyCondition( System.Windows.Automation.ValuePattern.ValueProperty, cmdlet.Value, // 20130121 //PropertyConditionFlags.IgnoreCase); // 20130127 flags); WriteVerbose(cmdlet, "ValueProperty '" + cmdlet.Value + "' is used"); conditionsCounter++; } // 20130128 //if (conditionsCounter > 1) // if there is more than one condition excepting ctrlTypeCondition if (1 < conditionsCounter) { try { System.Collections.ArrayList l = new System.Collections.ArrayList(); if (classCondition != null)l.Add(classCondition); // 20130128 //if (ctrlTypeCondition != null)l.Add(ctrlTypeCondition); if (titleCondition != null)l.Add(titleCondition); if (autoIdCondition != null)l.Add(autoIdCondition); // 20130127 if (null != valueCondition)l.Add(valueCondition); System.Type t = typeof(System.Windows.Automation.Condition); System.Windows.Automation.Condition[] conds = ((System.Windows.Automation.Condition[])l.ToArray(t)); // 20130128 if (AndVsOr) { andConditions = new System.Windows.Automation.AndCondition(conds); } else { orConditions = new System.Windows.Automation.OrCondition(conds); } // 20130128 // if (null == ctrlTypeCondition) { // //var ctrlTypeCond = // //new Condi // } else { // //var ctrlTypeCond = // } if (null != andConditions) { allConditions = new System.Windows.Automation.AndCondition( null == ctrlTypeCondition ? Condition.TrueCondition : ctrlTypeCondition, andConditions); } if (null != orConditions) { allConditions = new System.Windows.Automation.AndCondition( null == ctrlTypeCondition ? Condition.TrueCondition : ctrlTypeCondition, orConditions); } //} // 20130128 //conditions = // new System.Windows.Automation.AndCondition(conds); WriteVerbose(cmdlet, "used conditions " + "ClassName = '" + classCondition.Value + "', " + "ControlType = '" + ctrlTypeCondition.Value + "', " + "Name = '" + titleCondition.Value + "', " + "AutomationId = '" + autoIdCondition.Value + "', " + //"'"); // 20130127 "Value = '" + valueCondition.Value + "'"); } catch (Exception eConditions) { WriteDebug(cmdlet, "conditions related exception " + eConditions.Message); } // 20130128 //} else if (conditionsCounter == 1) //} else if ((1 == conditionsCounter) || (0 == conditionsCounter && null != ctrlTypeCondition)) // 20130128 } else if (1 == conditionsCounter && null != ctrlTypeCondition) { if (classCondition != null) { allConditions = new AndCondition(classCondition, ctrlTypeCondition); } else if (titleCondition != null) { allConditions = new AndCondition(titleCondition, ctrlTypeCondition); } else if (autoIdCondition != null) { allConditions = new AndCondition(autoIdCondition, ctrlTypeCondition); } else if (null != valueCondition) { allConditions = new AndCondition(valueCondition, ctrlTypeCondition); } WriteVerbose(cmdlet, "conditions: ctrlTypeCondition + a condition"); // 20130128 } else if ((0 == conditionsCounter && null != ctrlTypeCondition) || (1 == conditionsCounter && null == ctrlTypeCondition)) { if (classCondition != null) { condition = classCondition; } else if (ctrlTypeCondition != null) { condition = ctrlTypeCondition; } else if (titleCondition != null) { condition = titleCondition; } else if (autoIdCondition != null) { condition = autoIdCondition; } // 20130127 else if (null != valueCondition) { condition = valueCondition; } WriteVerbose(cmdlet, "condition " + condition.GetType().Name + " '" + condition.Value + "' is used"); } // 20130128 //else if (conditionsCounter == 0) else if (0 == conditionsCounter && null == ctrlTypeCondition) { WriteVerbose(cmdlet, "neither ControlType nor Class nor Name are present"); return (new AndCondition(Condition.TrueCondition, Condition.TrueCondition)); } try { Condition[] tempConditions = null; if (null != allConditions) { tempConditions = allConditions.GetConditions(); conditionsToReturn = allConditions; } else if (null != andConditions) { tempConditions = andConditions.GetConditions(); conditionsToReturn = andConditions; } else if (null != orConditions) { tempConditions = orConditions.GetConditions(); conditionsToReturn = orConditions; } else if (condition != null) { WriteVerbose(cmdlet, "conditions (only one): " + condition.Property.ProgrammaticName + " = " + condition.Value.ToString()); // 20130128 //andConditions = allConditions = new AndCondition(condition, Condition.TrueCondition); // 20130128 conditionsToReturn = allConditions; } // 20130128 if (null != tempConditions) { for (int i = 0; i < tempConditions.Length; i++) { WriteVerbose(cmdlet, "condition: " + tempConditions[i].ToString()); } } // 20130128 //return andConditions; return conditionsToReturn; } catch { WriteVerbose(cmdlet, "conditions or condition are null"); //return null; // 20130128 //return andConditions; return conditionsToReturn; } }
protected void displayConditions( GetControlCmdletBase cmdlet, AndCondition conditions, string description) { try { Condition[] conds = conditions.GetConditions(); for (int i = 0; i < conds.Length; i++) { cmdlet.WriteVerbose(cmdlet, "<<<< displaying conditions '" + description + "' >>>>"); cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Property.ProgrammaticName); cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Value.ToString()); cmdlet.WriteVerbose(cmdlet, (conds[i] as PropertyCondition).Flags.ToString()); } } catch {} }
public ScrollAxis GetScrollAxis(OrientationType orientation) { return (ScrollAxis)STAHelper.Invoke( delegate() { if(!scrollAxes.ContainsKey(orientation)) { object pattern; if(AutomationElement.TryGetCurrentPattern(ScrollPattern.Pattern, out pattern)) { scrollAxes[orientation] = new ScrollPatternAxis((ScrollPattern)pattern, orientation); } else if(ControlType == ControlType.ScrollBar) { if(orientation == (OrientationType)this[AutomationElement.OrientationProperty]) scrollAxes[orientation] = new ScrollBarAxis(AutomationElement); else throw new ArgumentException("Cannot get "+orientation+" scroll-axis for a scrollbar that is not "+orientation); } else if (ControlType == ControlType.Pane && Class == "ScrollBar") { scrollAxes[orientation] = new PaneScrollAxis(AutomationElement); } else { Condition scrollBarCondition = new AndCondition( new PropertyCondition2(AutomationElement.OrientationProperty, orientation), new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.ScrollBar) ); Condition scrollPaneCondition = new AndCondition( new PropertyCondition2(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition2(AutomationElement.ClassNameProperty, "ScrollBar") ); Condition scrollPatternCondition = new PropertyCondition2(AutomationElement.IsScrollPatternAvailableProperty, true); Condition condition = new OrCondition(scrollBarCondition, scrollPaneCondition, scrollPatternCondition); List<AutomationElement> matches = Twin.View.Search.FindAll(AutomationElement, TreeScope.Descendants, 1 ,condition, (int)AutomationElement.GetCurrentPropertyValue(AutomationElement.ProcessIdProperty)); for(int i=0; i<matches.Count; i++) { if(matches[i].GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) != ControlType.Pane) continue; if((bool)matches[i].GetCurrentPropertyValue(AutomationElement.IsScrollPatternAvailableProperty)) continue; Rect bounds = (Rect)matches[i].GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty); if(orientation == OrientationType.Horizontal && bounds.Height > bounds.Width) matches.RemoveAt(i--); if(orientation == OrientationType.Vertical && bounds.Width > bounds.Height) matches.RemoveAt(i--); } if (matches.Count == 0) return null; if (matches.Count > 1) throw new ArgumentException("Scrollable Axis for element ambiguous"); return Element.Create(matches[0], processId).GetScrollAxis(orientation); } } return scrollAxes[orientation]; } ); }
//************************************************************************************************************************************************************** public static AutomationElement UIA_GetChildWindow(AutomationElement appWindow, string childWindowName) { AutomationElement childWindow = null; try { PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window); PropertyCondition windowNameCondition = new PropertyCondition(AutomationElement.NameProperty, childWindowName); AndCondition windowCondition = new AndCondition(windowTypeCondition, windowNameCondition); AutomationElement window = appWindow.FindFirst(TreeScope.Children, windowCondition); AutomationElementCollection windows = appWindow.FindAll(TreeScope.Descendants, windowTypeCondition); foreach (AutomationElement w in windows) { if (w.Current.Name.Equals(childWindowName) || w.Current.Name.Contains(childWindowName)) { childWindow = w; break; } } return childWindow; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
//************************************************************************************************************************************************************** public static AutomationElement UIA_GetAppWindow(string windowName) { try { PropertyCondition windowTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window); PropertyCondition windowAutomationIDCondition = new PropertyCondition(AutomationElement.NameProperty, windowName); AndCondition windowCondition = new AndCondition(windowTypeCondition, windowAutomationIDCondition); AutomationElement window = AutomationElement.RootElement.FindFirst(TreeScope.Children, windowCondition); return window; } catch (Exception e) { String sMessage = e.Message; LastException.SetLastError(sMessage); throw new Exception(sMessage); } }
public DialogMonitorResult ExecuteDialogSlapDown(Action<string> ifSlappedAction) { var noActionTaken = DialogMonitorResult.NoSlapdownAction(); AutomationElement appWindow; Process[] processesByName = Process.GetProcessesByName("XDE"); if (processesByName.Any()) { int processId = processesByName.First().Id; var processIdCond = new PropertyCondition(AutomationElement.ProcessIdProperty, processId); appWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, processIdCond); if (appWindow == null) { _logger.Debug("COULD NOT FIND THE AUTOMATION ELEMENT FOR processId {0}".FormatWith(processId)); return noActionTaken; } } else { return noActionTaken; } if (appWindow.Current.Name.Contains("Assertion Failed")) return noActionTaken; var yesButtonCond = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "button"); var yesButtonNameCond = new PropertyCondition(AutomationElement.NameProperty, "Yes"); var yesCond = new AndCondition(yesButtonCond, yesButtonNameCond); var yesButton = appWindow.FindFirst(TreeScope.Children, yesCond); if (yesButton == null) { _logger.Debug("COULD NOT FIND THE yesButton"); return noActionTaken; } var buttonClicInvokePattern = yesButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; if (buttonClicInvokePattern == null) { _logger.Debug("COULD NOT FIND THE buttonClicInvokePattern"); return noActionTaken; } string caption = appWindow.GetNamePropertyOf(AutomationTypes.ControlText); string text = appWindow.GetNamePropertyOf(AutomationTypes.ControlTitleBar); string msg = @"Windows Phone Emulator dialog was automatically closed. Caption: {0} Message: {1}".FormatWith(caption, text); ifSlappedAction(msg); _logger.Debug("Clicking Yes on a dialog (MessageBox)"); // Close the dialgo by clicking Yes buttonClicInvokePattern.Invoke(); return new DialogMonitorResult { WasActionTaken = true, Message = msg, }; }
private static IEnumerable<string> GetBrowserUrls() { HashSet<string> urls = new HashSet<string>(); // FireFox foreach (WindowDetails window in WindowDetails.GetAllWindows("MozillaWindowClass")) { if (window.Text.Length == 0) { continue; } AutomationElement currentElement = AutomationElement.FromHandle(window.Handle); Condition conditionCustom = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); for (int i = 5; i > 0 && currentElement != null; i--) { currentElement = currentElement.FindFirst(TreeScope.Children, conditionCustom); } if (currentElement == null) { continue; } Condition conditionDocument = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), new PropertyCondition(AutomationElement.IsOffscreenProperty, false)); AutomationElement docElement = currentElement.FindFirst(TreeScope.Children, conditionDocument); if (docElement == null) { continue; } foreach (AutomationPattern pattern in docElement.GetSupportedPatterns()) { if (pattern.ProgrammaticName != "ValuePatternIdentifiers.Pattern") { continue; } string url = (docElement.GetCurrentPattern(pattern) as ValuePattern).Current.Value.ToString(); if (!string.IsNullOrEmpty(url)) { urls.Add(url); break; } } } foreach(string url in IEHelper.GetIEUrls()) { urls.Add(url); } return urls; }