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 void ShouldDescribeCompoundConditionsUsingOr() { var nameCondition = new PropertyCondition(AutomationElement.NameProperty, "Wubble"); var controlTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window); var condition = new OrCondition(nameCondition, controlTypeCondition); var expected = "(Name='Wubble' or ControlType='" + ControlType.Window.Id + "')"; Assert.AreEqual(expected, new ConditionDescriber().Describe(condition)); }
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 void getOrConditions(string searchString, string controlType) { ResultOrCondition = null; GetControlCmdletBase cmdlet = new GetControlCmdletBase {ContainsText = searchString }; CommonCmdletBase common = new CommonCmdletBase(); // 20131129 // ResultOrCondition = // (common.GetControlConditionsForExactSearch(cmdlet, controlType, cmdlet.CaseSensitive, false) as OrCondition); ResultOrCondition = // common.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition; ControlSearcher.GetTextSearchCondition(searchString, new string[] { controlType }, cmdlet.CaseSensitive) as OrCondition; }
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"); }
public void OrConditionTest() { Condition condition = Condition.TrueCondition; Condition condition2 = OrCondition.FalseCondition; OrCondition target = new OrCondition(condition, condition2); Condition[] actual; actual = target.GetConditions(); Assert.IsNotNull(actual); Assert.AreEqual(actual.Length, 2); // Negative test - include a null try { target = new OrCondition(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 int ExpandTableCell(String windowName, String objName, int index) { Object pattern; AutomationElement element = null; AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition condition = new OrCondition(prop1, prop2); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll(TreeScope.Children, condition); try { element = c[index]; } catch (IndexOutOfRangeException) { throw new XmlRpcFaultException(123, "Index out of range: " + index); } catch (ArgumentException) { throw new XmlRpcFaultException(123, "Index out of range: " + index); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + index); } finally { c = null; childHandle = null; prop1 = prop2 = condition = null; } if (element != null) { LogMessage(element.Current.Name + " : " + element.Current.ControlType.ProgrammaticName); if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); if (((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Expanded) ((ExpandCollapsePattern)pattern).Collapse(); else if (((ExpandCollapsePattern)pattern).Current.ExpandCollapseState == ExpandCollapseState.Collapsed) ((ExpandCollapsePattern)pattern).Expand(); return 1; } } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) throw; else throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } finally { element = null; pattern = null; } throw new XmlRpcFaultException(123, "Unable to expand item."); }
private Condition GetCondition() { var info = this.infoList[0]; Condition result = new PropertyCondition(info.Property, info.Value); for (var i = 1; i < this.infoList.Count; ++i) { info = this.infoList[i]; var condition = new PropertyCondition(info.Property, info.Value); switch (info.ConditionType) { case ConditionType.And: result = new AndCondition(result, condition); break; case ConditionType.Or: result = new OrCondition(result, condition); break; default: throw new CruciatusException("ConditionType ERROR"); } } return result; }
public int[] GetCellSize(String windowName, String objName, int row, int column = 0) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElement element = null; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition prop3 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.DataItem); Condition prop4 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Text); Condition prop5 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Custom); Condition condition1 = new OrCondition(prop1, prop2, prop3, prop5); Condition condition2 = new OrCondition(prop4, prop5); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll( TreeScope.Children, condition1); element = c[row]; c = element.FindAll(TreeScope.Children, condition2); element = c[column]; c = null; if (element != null) { Rect rect = childHandle.Current.BoundingRectangle; return new int[] { (int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height }; } } catch (IndexOutOfRangeException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (ArgumentException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } finally { element = childHandle = null; prop1 = prop2 = prop3 = prop4 = prop5 = null; condition1 = condition2 = null; } throw new XmlRpcFaultException(123, "Unable to get item size."); }
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 int GetTableRowIndex(String windowName, String objName, String cellValue) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElementCollection c1, c2; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition condition1 = new OrCondition(prop1, prop2); Condition condition2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Text); try { int count = GetRowCount(windowName, objName); childHandle.SetFocus(); c1 = childHandle.FindAll(TreeScope.Children, condition1); for (int i = 0; i < count; i++) { c2 = c1[i].FindAll(TreeScope.Children, condition2); for (int j = 0; j < c2.Count; j++) { if (utils.common.WildcardMatch(c2[j].Current.Name, cellValue)) return i; } } } catch (Exception ex) { LogMessage(ex); } finally { c1 = c2 = null; childHandle = null; prop1 = prop2 = condition1 = condition2 = null; } throw new XmlRpcFaultException(123, "Unable to get row index: " + cellValue); }
public override void ExitOrCondition(PrevailParser.OrConditionContext context) { base.ExitOrCondition(context); var right = _conditionStack.Pop(); var left = _conditionStack.Pop(); var or = new OrCondition(new Condition[] { left, right }); _conditionStack.Push(or); }
private ArrayList getWindowCollectionByName(string[] windowNames, string automationId, string className, bool recurse) { System.Windows.Automation.OrCondition conditionsSet = null; System.Collections.ArrayList aeWndCollectionByTitle = new System.Collections.ArrayList(); System.Collections.ArrayList resultCollection = new System.Collections.ArrayList(); // 20130220 if (null == windowNames) { windowNames = new string[]{ string.Empty }; } // 20120824 foreach (string windowTitle in windowNames) { WriteVerbose(this, "processName.Length == 0"); #region changed 20120608 // conditionsTitle = // new AndCondition( // new System.Windows.Automation.OrCondition( // new System.Windows.Automation.PropertyCondition( // System.Windows.Automation.AutomationElement.ControlTypeProperty, // System.Windows.Automation.ControlType.Window), // new System.Windows.Automation.PropertyCondition( // System.Windows.Automation.AutomationElement.ControlTypeProperty, // System.Windows.Automation.ControlType.Pane), // new System.Windows.Automation.PropertyCondition( // System.Windows.Automation.AutomationElement.ControlTypeProperty, // System.Windows.Automation.ControlType.Menu)), // new PropertyCondition( // System.Windows.Automation.AutomationElement.NameProperty, // title)); #endregion changed 20120608 // 20130221 if (recurse) { conditionsSet = new System.Windows.Automation.OrCondition( new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Window), System.Windows.Automation.Condition.FalseCondition); } else { conditionsSet = new System.Windows.Automation.OrCondition( new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Window), new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Pane), new System.Windows.Automation.PropertyCondition( System.Windows.Automation.AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Menu)); } WriteVerbose(this, "trying to get window: by title = " + // 20120824 //title); windowTitle); #region changed 20120608 // aeWndByTitle = // rootElement.FindFirst(System.Windows.Automation.TreeScope.Children, // conditionsTitle); #endregion changed 20120608 // 20130221 AutomationElementCollection aeWndCollection = null; if (recurse) { aeWndCollection = rootElement.FindAll(TreeScope.Descendants, conditionsSet); } else { //AutomationElementCollection aeWndCollection = aeWndCollection = rootElement.FindAll(TreeScope.Children, conditionsSet); } #region commented // 20130220 // WildcardOptions options; // // if (caseSensitive) { // // options = // // WildcardOptions.Compiled; // // } else { // options = // WildcardOptions.IgnoreCase | // WildcardOptions.Compiled; // // } // WildcardPattern wildcardName = // // 20120824 // //new WildcardPattern(title,options); // new WildcardPattern(windowTitle, options); // // //// bool matched = false; //// if (name.Length > 0 && wildcardName.IsMatch(element.Current.Name)) { //// matched = true; //// } else if (automationId.Length > 0 && //// wildcardAutomationId.IsMatch(element.Current.AutomationId)) { //// matched = true; //// } else if (className.Length > 0 && //// wildcardClass.IsMatch(element.Current.ClassName)) { //// matched = true; //// } //// //// if (matched) { //// if (onlyOneResult) { //// result = element; //// } else { //// WriteObject(this, element); //// } //// } // // if (aeWndCollection.Count > 0) { // // WriteVerbose(this, "aeWndCollection.Count > 0"); // // foreach (AutomationElement wndInColleciton in aeWndCollection) { // if (wndInColleciton.Current.Name != null && // wndInColleciton.Current.Name != string.Empty && // wndInColleciton.Current.Name.Length > 0 && // wildcardName.IsMatch(wndInColleciton.Current.Name)) { // // 20120824 // //aeWndByTitle = wndInColleciton; // //break; // aeWndCollectionByTitle.Add(wndInColleciton); // } // } // } //// //else { // WriteVerbose(this, "aeWndCollection.Count == 0"); //} //// // if (null != aeWndCollection && 0 < aeWndCollection.Count) { // // System.Collections.ArrayList tempCollection = // new System.Collections.ArrayList(); // System.Windows.Automation.AndCondition conditionsForWildCards = // this.getControlConditions(this, string.Empty, false, true) as AndCondition; // // SearchByWildcardViaUIA((GetCmdletBase)this, ref tempCollection, AutomationElement.RootElement, windowTitle, automationId, className, string.Empty, conditionsForWildCards); // // if (null != tempCollection && 0 < tempCollection.Count) { // aeWndCollectionByTitle.AddRange(tempCollection); // } // } #endregion commented this.WriteVerbose(this, "trying to run the returnOnlyRightElements method"); this.WriteVerbose(this, "collected " + aeWndCollection.Count.ToString() + " elements for further selection"); aeWndCollectionByTitle = //(this as GetCmdletBase).returnOnlyRightElements( //this.ReturnOnlyRightElements( HasTimeoutCmdletBase.ReturnOnlyRightElements( // 20130513 this, aeWndCollection, windowTitle, automationId, className, string.Empty, (new string[]{ "Window", "Pane", "Menu" }), false); this.WriteVerbose(this, "after running the returnOnlyRightElements method"); this.WriteVerbose(this, "collected " + aeWndCollectionByTitle.Count.ToString() + " elements"); // 20120831 if (null != aeWndCollectionByTitle && 0 < aeWndCollectionByTitle.Count) { // 20120824 foreach (AutomationElement aeWndByTitle in aeWndCollectionByTitle) { // 20120831 //AutomationElement tempElement = null; if (aeWndByTitle != null && (int)aeWndByTitle.Current.ProcessId > 0) { WriteVerbose(this, "aeWndByTitle: " + aeWndByTitle.Current.Name + // 20120824 //" is caught by title = " + title); " is caught be title = " + windowTitle); // 20120824 resultCollection.Add(aeWndByTitle); } } // 20120831 } else { // 20120831 AutomationElement tempElement = null; // one more attempt using the FindWindow function System.IntPtr wndHandle = // 20120824 //FindWindowByCaption(System.IntPtr.Zero, title); FindWindowByCaption(System.IntPtr.Zero, windowTitle); if (wndHandle != null && wndHandle != System.IntPtr.Zero) { // 20120824 //aeWndByTitle = tempElement = AutomationElement.FromHandle(wndHandle); } // 20120824 //if (aeWndByTitle != null && (int)aeWndByTitle.Current.ProcessId > 0) { if (null != tempElement && (int)tempElement.Current.ProcessId > 0) { WriteVerbose(this, "aeWndByTitle: " + // 20120824 //aeWndByTitle.Current.Name + // 20120824 //" is caught by title = " + title + " is caught by title = " + windowTitle + " using the FindWindow function"); // 20120824 resultCollection.Add(tempElement); } } // 20120831 //} // 20120824 } // 20120824 // 20120824 //return aeWndByTitle; return resultCollection; }
public String GetCellValue(String windowName, String objName, int row, int column = 0) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElement element = null; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition condition1 = new OrCondition(prop1, prop2); Condition condition2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Text); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll( TreeScope.Children, condition1); element = c[row]; c = element.FindAll(TreeScope.Children, condition2); element = c[column]; c = null; if (element != null) return element.Current.Name; } catch (IndexOutOfRangeException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (ArgumentException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } finally { element = childHandle = null; prop1 = prop2 = condition1 = condition2 = null; } throw new XmlRpcFaultException(123, "Unable to get item value."); }
public int GetRowCount(String windowName, String objName) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElementCollection c; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition condition = new OrCondition(prop1, prop2); try { c = childHandle.FindAll(TreeScope.Children, condition); if (c == null) throw new XmlRpcFaultException(123, "Unable to get row count."); return c.Count; } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) throw; else throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } finally { c = null; childHandle = null; prop1 = prop2 = condition = null; } }
public int DoubleClickRowIndex(String windowName, String objName, int row, int column = 0) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElement element = null; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition prop3 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.DataItem); Condition prop4 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Text); Condition prop5 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Custom); Condition condition1 = new OrCondition(prop1, prop2, prop3, prop5); Condition condition2 = new OrCondition(prop4, prop5); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll( TreeScope.Children, condition1); element = c[row]; c = element.FindAll(TreeScope.Children, condition2); element = c[column]; c = null; if (element != null) { Mouse mouse = new Mouse(utils); Rect rect = element.Current.BoundingRectangle; mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2), (int)(rect.Y + rect.Height / 2), "b1d"); return 1; } } catch (IndexOutOfRangeException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (ArgumentException) { throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } finally { element = childHandle = null; prop1 = prop2 = prop3 = prop4 = prop5 = null; condition1 = condition2 = null; } throw new XmlRpcFaultException(123, "Unable to find the item in list: " + row); }
public int SelectRowIndex(String windowName, String objName, int index) { Object pattern; AutomationElement element = null; AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition condition = new OrCondition(prop1, prop2); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll(TreeScope.Children, condition); try { element = c[index]; element.SetFocus(); } catch (IndexOutOfRangeException) { throw new XmlRpcFaultException(123, "Index out of range: " + index); } catch (ArgumentException) { throw new XmlRpcFaultException(123, "Index out of range: " + index); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + index); } if (element != null) { LogMessage(element.Current.Name + " : " + element.Current.ControlType.ProgrammaticName); if (element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { LogMessage("SelectionItemPattern"); element.SetFocus(); //((SelectionItemPattern)pattern).Select(); // NOTE: Work around, as the above doesn't seem to work // with UIAComWrapper and UIAComWrapper is required // to Edit value in Spin control utils.InternalClick(element); return 1; } else if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); ((ExpandCollapsePattern)pattern).Expand(); element.SetFocus(); return 1; } } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) throw; else throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } finally { pattern = null; element = childHandle = null; prop1 = prop2 = condition = null; } throw new XmlRpcFaultException(123, "Unable to select item."); }
public String GetCellValue(String windowName, String objName, int row, int column = 0) { AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } AutomationElement element = null; Condition prop1 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.ListItem); Condition prop2 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.TreeItem); Condition prop3 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.DataItem); Condition prop4 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Text); Condition prop5 = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Custom); Condition condition1 = new OrCondition(prop1, prop2, prop3, prop5); Condition condition2 = new OrCondition(prop4, prop5); try { childHandle.SetFocus(); AutomationElementCollection c = childHandle.FindAll( TreeScope.Children, condition1); element = c[row]; c = element.FindAll(TreeScope.Children, condition2); element = c[column]; c = null; if (element != null) { if (element.Current.ControlType == ControlType.Text) return element.Current.Name; else { // Specific to DataGrid of Windows Forms element.SetFocus(); Mouse mouse = new Mouse(utils); Rect rect = element.Current.BoundingRectangle; utils.InternalWait(1); mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2), (int)(rect.Y + rect.Height / 2), "b1c"); utils.InternalWait(1); // Only on second b1c, it becomes edit control // though the edit control is not under current widget // its created in different hierarchy altogether // So, its required to do (from python) // gettextvalue("Window Name", "txtEditingControl") mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2), (int)(rect.Y + rect.Height / 2), "b1c"); return ""; } } } catch (IndexOutOfRangeException ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (ArgumentException ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } catch (Exception ex) { LogMessage(ex); throw new XmlRpcFaultException(123, "Index out of range: " + "(" + row + ", " + column + ")"); } finally { element = childHandle = null; prop1 = prop2 = prop3 = prop4 = prop5 = null; condition1 = condition2 = null; } throw new XmlRpcFaultException(123, "Unable to get item value."); }
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; } }
private static string GetBrowserFirefoxUrl(IntPtr hWnd) { // Address and search bar // Введите поисковый запрос или адрес try { // хватаемся за адресную строку var ff = AutomationElement.FromHandle(hWnd); var textCondition = new OrCondition( new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"), new PropertyCondition(AutomationElement.NameProperty, "Введите поисковый запрос или адрес")); var editCondition = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), textCondition); var edit = ff.FindFirst(TreeScope.Subtree, editCondition); // не считается, если туда кто-то печатает if ((bool)edit.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty)) return null; // пытаемся прочитать адрес и если он похож на настоящий, то возвращаем его var url = ((ValuePattern)edit.GetCurrentPattern(ValuePatternIdentifiers.Pattern)).Current.Value; if (url == "") return null; if (!Regex.IsMatch(url, addrRegex)) return null; if (!url.StartsWith("http")) url = "http://" + url; return url; } catch { return null; } }