public static string buttonClick(string ClassName, string WindowName, System.Windows.Point p) { //AutomationElement ae = AutomationElement.FromPoint(p); //System.Windows.Point pt = ae.GetClickablePoint(); MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); return("Done"); }
public static string ListItemSelect(string wName, string lName) { ControlOp co = new ControlOp(lName, ControlType.ListItem); 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(lName)) { 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 { return("ListItem not found"); } return("ListItem not found"); }
public static string TabSwitch(string wName, string tName) { ControlOp co = new ControlOp(tName, ControlType.TabItem); 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) { Console.WriteLine(ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString()); if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == tName) { // SelectionItemPattern pattern; // pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; // pattern.Select(); // return "Done"; Console.WriteLine("Find"); MouseClick.DoMouseClick((int)(ae.Current.BoundingRectangle.X + ae.Current.BoundingRectangle.Width / 2), (int)(ae.Current.BoundingRectangle.Y + ae.Current.BoundingRectangle.Height / 2)); return("Done"); } } } } else { return("TabPage not found"); } return("TabPage not found1"); }
private static void buttonAction(AutomationElement ae) { // InvokePattern pattern; // pattern = ae.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; // pattern.Invoke(); MouseClick.DoMouseClick((int)(ae.Current.BoundingRectangle.X + ae.Current.BoundingRectangle.Width / 2), (int)(ae.Current.BoundingRectangle.Y + ae.Current.BoundingRectangle.Height / 2)); }
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"); }
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"); }