public static string SelectItemByCount(string WindowName, string lID, int count) { int maxCount = ItemCount(WindowName, lID); AutomationElement item1 = TreeWalker.ControlViewWalker.GetFirstChild(getListElement(WindowName, lID)); if (count <= maxCount && count > 0) { if (count == 1) { SelectionItemPattern pattern; pattern = item1.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); try { System.Windows.Point p = item1.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); } catch (NoClickablePointException) { KeyboardOp.sendKey("{enter}"); } return("Done"); } else { for (int index = 1; index < count; index++) { item1 = TreeWalker.ControlViewWalker.GetNextSibling(item1); } SelectionItemPattern pattern; pattern = item1.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); try { System.Windows.Point p = item1.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); } catch (NoClickablePointException) { KeyboardOp.sendKey("{enter}"); } return("Done"); } } return("Item not found"); }
//前提条件: 所有节点全部展开,所要选择的节点不能被遮挡住 public static string TreeItemSelect(string wName, string FlexTreeName, string ItemName) { ControlOp co = new ControlOp(FlexTreeName, ControlType.Tree); List <IntPtr> hWnd = co.GetChildWindow(wName); if (hWnd.Count != 0) { for (int i = hWnd.Count - 1; i >= 0; i--) { AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); foreach (AutomationElement ae in aec) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(FlexTreeName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == FlexTreeName) { Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem)); AutomationElementCollection elementCollection = ae.FindAll(TreeScope.Children, conditions); foreach (AutomationElement auto in elementCollection) { if (auto.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { try { System.Windows.Point p = auto.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); } catch { } return("Done"); } } } } } } return("Item not found"); }
public static string IconDragAndDrop(string iconName, int targetX, int targetY) { System.Windows.Point p = GetClickablePoint(iconName); MouseClick.DoDragandDrop(Convert.ToInt32(p.X), Convert.ToInt32(p.Y), targetX, targetY); return("Done"); }
public static string IconRightClick(string iconName) { System.Windows.Point p = GetClickablePoint(iconName); MouseClick.DoMouseRightClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); }
public static string TreeItemSelect(string wName, string ItemName, int layer) { ControlOp co = new ControlOp(ItemName, ControlType.TreeItem); List <IntPtr> hWnd = co.GetChildWindow(wName); if (hWnd.Count != 0) { for (int i = hWnd.Count - 1; i >= 0; i--) { AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); foreach (AutomationElement ae in aec) { if (layer == 1) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { SelectionItemPattern pattern; pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); System.Windows.Point p = ae.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); } } else if (layer == 2) { AutomationElementCollection items = co.FindByMultipleConditions(ae); foreach (AutomationElement Treeitem in items) { if (Treeitem.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { SelectionItemPattern pattern; pattern = Treeitem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); System.Windows.Point p = Treeitem.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); } } } else if (layer == 3) { AutomationElementCollection items = co.FindByMultipleConditions(ae); foreach (AutomationElement Treeitem in items) { AutomationElementCollection items_third = co.FindByMultipleConditions(Treeitem); foreach (AutomationElement Treeitem_third in items_third) { if (Treeitem_third.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { SelectionItemPattern pattern; pattern = Treeitem_third.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); System.Windows.Point p = Treeitem_third.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); } } } } } } } else { return("Tree Item not found"); } return("Tree Item not found"); }
private static string ComboBoxItemSelect(string WindowName, string comboName, string ItemName, int itemCount) { ControlOp co = new ControlOp(comboName, ControlType.ComboBox); List <IntPtr> hWnd = co.GetChildWindow(WindowName); if (hWnd.Count != 0) { for (int i = hWnd.Count - 1; i >= 0; i--) { AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); foreach (AutomationElement ae in aec) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(comboName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == comboName) { try { ExpandCollapsePattern pattern; pattern = ae.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; pattern.Expand(); Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List)); AutomationElementCollection elementCollection = ae.FindAll(TreeScope.Children, conditions); // Find all children that match the specified conditions.. if (itemCount == 0) { foreach (AutomationElement e in elementCollection) { Condition conditionsItem = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); AutomationElementCollection elementCollectionItem = e.FindAll(TreeScope.Children, conditionsItem); foreach (AutomationElement auto in elementCollectionItem) { if (auto.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { System.Windows.Point p = auto.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); } } } } else { string lID = elementCollection[0].GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString(); ListOP.SelectItemByCount(WindowName, lID, itemCount); return("Done"); } } catch (InvalidOperationException) { //Flex testing Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); AutomationElementCollection elementCollection = ae.FindAll(TreeScope.Children, conditions); foreach (AutomationElement auto in elementCollection) { if (auto.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(ItemName)) { InvokePattern pattern; pattern = auto.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; pattern.Invoke(); return("Done"); } } } } } } } else { return("Item not found"); } return("Item not found"); }