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"); }
private static string EditInOut(AutomationElement ae, bool isOut, string key, string windowName) { if (isOut) { ValuePattern pattern; pattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; return(pattern.Current.Value); } else { ValuePattern pattern; pattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; Utility.wait(2); try { pattern.SetValue(key); } catch (InvalidOperationException) { ControlOp co = new ControlOp(); co.SetForeground(windowName); Utility.wait(2); KeyboardOp.sendKey(key); Utility.wait(2); return("key sent"); } return("No key sent"); } }
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"); }
public bool exist(ControlOp co, string WindowName, int seconds) { int interval = seconds / 2; while (interval != 0) { List <IntPtr> hWnd = co.GetChildWindow(WindowName); if (hWnd.Count != 0) { for (int i = hWnd.Count - 1; i >= 0; i--) { if (hWnd[i] != IntPtr.Zero) { try { AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); foreach (AutomationElement ae in aec) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(co._ControlName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == co._ControlName) { return(true); } } } catch (ElementNotAvailableException) { return(false); } } } } Utility.wait(1); interval--; } return(false); }
public string getAllControlName(ControlOp co, string WindowName) { List <IntPtr> hWnd = co.GetChildWindow(WindowName); if (hWnd.Count != 0) { string controlName = ""; for (int i = hWnd.Count - 1; i >= 0; i--) { AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); foreach (AutomationElement ae in aec) { controlName = controlName + "|" + "Name: " + ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() + " ID: " + ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString(); } } if (controlName.Length != 0) { controlName = controlName.Remove(0, 1); return(controlName); } else { return("Nothing"); } } else { return("Nothing"); } }
public static AutomationElement getListElement(string WindowName, string lID) { ControlOp co = new ControlOp(lID, ControlType.List); 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.AutomationIdProperty).ToString().Contains(lID)) { return(ae); } } } } else { return(null); } return(null); }
public static string RadioSelect(string wName, string rName) { ControlOp co = new ControlOp(rName, ControlType.RadioButton); 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(rName)) { try { SelectionItemPattern pattern; pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); } catch { InvokePattern pattern; pattern = ae.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; pattern.Invoke(); } return("Done"); } } } } else { return("Radio Button not found"); } return("Radio Button not found"); }
public void Switch(string windowName) { ControlOp co = new ControlOp(); ITargetLocator target = driver.SwitchTo(); target.Window(co.FindWindowHandle(windowName).ToString("X8")); }
public void Maximize() { //Console.WriteLine(driver.Title); // ButtonOp.buttonClick(driver.Title + " - Microsoft Internet Explorer provided by Hewlett-Packard", "Maximize"); ControlOp co = new ControlOp(); //co.MaximizeWindow(co.FindWindowHandle(null, driver.Title + " - Microsoft Internet Explorer provided by Hewlett-Packard")); co.MaximizeWindow(); }
private static string EditInOutPut(string WindownName, string editName, string key, bool ispartEditName, bool isout) { ControlOp co = new ControlOp(editName, ControlType.Edit); List <IntPtr> hWnd = co.GetChildWindow(WindownName); string result = ""; 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 (ispartEditName) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(editName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == editName) { if (isout) { result = EditInOut(ae, true, key, WindownName); return(result); } else { result = EditInOut(ae, false, key, WindownName); return(result); } } } else { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == editName || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == editName) { if (isout) { result = EditInOut(ae, true, key, WindownName); return(result); } else { result = EditInOut(ae, false, key, WindownName); return(result); } } } } } return(result); } else { return("Edit control not found"); } }
public static bool Exsit(string WindowName, string buttonName, int seconds) { ControlOp co = new ControlOp(buttonName, ControlType.Button); if (seconds == 0) { return(co.exist(co, WindowName)); } else { return(co.exist(co, WindowName, seconds)); } }
private static string CheckboxToggleOnOff(string wName, string cName, ToggleState ts, bool isPartContainCheckedListItemName) { ControlOp co = new ControlOp(cName, 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 (isPartContainCheckedListItemName) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(cName)) { TogglePattern pattern; pattern = ae.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern; TogglePattern.TogglePatternInformation tpi = pattern.Current; if (tpi.ToggleState != ts) { pattern.Toggle(); } return("Done"); } } else { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == cName) { TogglePattern pattern; pattern = ae.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern; TogglePattern.TogglePatternInformation tpi = pattern.Current; if (tpi.ToggleState != ts) { pattern.Toggle(); } return("Done"); } } } } } else { return("ListItem not found"); } return("ListItem not found"); }
public static string CheckBoxToggle(string wName, string cName, bool isPartContainCheckedListItemName) { ControlOp co = new ControlOp(cName, 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 (isPartContainCheckedListItemName) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(cName)) { SelectionItemPattern pattern; pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); KeyboardOp.sendKey(" "); return("Done"); } } else { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == cName) { SelectionItemPattern pattern; pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; pattern.Select(); KeyboardOp.sendKey(" "); return("Done"); } } } } } else { return("ListItem not found"); } return("ListItem not found"); }
private static System.Windows.Point GetClickablePoint(string iconName) { IntPtr HWND3 = FindWindowEx(GetDesktopWindow(), (IntPtr)null, "Progman", null); IntPtr HWND = FindWindowEx(HWND3, (IntPtr)null, "SHELLDLL_DefView", null); IntPtr HWND2 = FindWindowEx(HWND, (IntPtr)null, "SysListView32", null); System.Windows.Point p = new System.Windows.Point(); ControlOp co = new ControlOp(iconName, ControlType.ListItem); AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(HWND2)); foreach (AutomationElement ae in aec) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(iconName)) { p = ae.GetClickablePoint(); return(p); } } return(p); }
public static string MenuClick(string className, string WindowName, string menuName) { ControlOp co = new ControlOp(menuName, ControlType.MenuBar); List <IntPtr> hWnd = co.GetChildWindow(className, 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.ControlTypeProperty) == ControlType.MenuBar) { Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem)); AutomationElementCollection TopMenu = ae.FindAll(TreeScope.Children, conditions); foreach (AutomationElement menuItem in TopMenu) { if (menuItem.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(menuName)) { //System.Windows.Point p = menuItem.GetClickablePoint(); //MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y)); ExpandCollapsePattern pattern; pattern = menuItem.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; pattern.Expand(); return("Done"); } } } } } } else { return("MenuItem not found"); } return("MenuItem not found"); }
public static string TabSwitch(string wName, string FlexTabName, string tName) { ControlOp co = new ControlOp(FlexTabName, ControlType.Tab); 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() == FlexTabName || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == FlexTabName) { Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.IsEnabledProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem)); AutomationElementCollection elementCollection = ae.FindAll(TreeScope.Children, conditions); foreach (AutomationElement auto in elementCollection) { if (auto.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == tName) { InvokePattern pattern; pattern = auto.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; pattern.Invoke(); return("Done"); } } } } } } else { return("TabPage not found"); } return("Finish"); }
private static string CheckBoxOnOff(string wName, string cName, ToggleState ts, bool isPartContainCheckboxName) { ControlOp co = new ControlOp(cName, ControlType.CheckBox); 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) { ControlAction(ae, isPartContainCheckboxName, ts, cName); //return "Done"; } } } else { return("Checkbox not found, hwnd"); } return("Checkbox Finish"); }
public static string PaneOutPut(string WindownName, string paneName, bool ispartPaneName) { ControlOp co = new ControlOp(paneName, ControlType.Pane); List <IntPtr> hWnd = co.GetChildWindow(WindownName); 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 (ispartPaneName) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(paneName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == paneName) { return(ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString()); } } else { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == paneName || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == paneName) { return(ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString()); } } } } return("Done"); } else { return("Pane control 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 bool Exsit(string ClassName, string WindowName, string lName) { ControlOp co = new ControlOp(lName, ControlType.ListItem); return(co.exist(co, WindowName)); }
public static bool Exsit(string WindowName, string lID) { ControlOp co = new ControlOp(lID, ControlType.List); return(co.exist(co, WindowName)); }
public static string GetCheckedListboxName(string WindowName) { ControlOp co = new ControlOp(ControlType.ListItem); return(co.getAllControlName(co, WindowName)); }
public static bool Exsit(string WindowName, string tName) { ControlOp co = new ControlOp(tName, ControlType.TabItem); return(co.exist(co, WindowName)); }
public ButtonOp(string WindowName) { ControlOp co = new ControlOp(); _hWnd = co.GetChildWindow(WindowName); }
public static string GetEditName(string wName) { ControlOp co = new ControlOp(ControlType.Edit); return(co.getAllControlName(co, wName)); }
public static bool Exsit(string WindowName, string editName) { ControlOp co = new ControlOp(editName, ControlType.Edit); return(co.exist(co, WindowName)); }
public static string buttonClick(string WindowName, string buttonName, bool isPartContainButtonName, int index) { ControlOp co = new ControlOp(buttonName, ControlType.Button); List <IntPtr> hWnd = co.GetChildWindow(WindowName); // Console.WriteLine(hWnd.Count.ToString()); if (hWnd.Count != 0) { for (int i = hWnd.Count - 1; i >= 0; i--) { // Console.WriteLine(hWnd[i].ToString("X8")); // Console.WriteLine(AutomationElement.FromHandle(hWnd[hWnd.Count - 2]).ToString("X8")); AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i])); // Console.WriteLine(aec.Count); if (index > 0) //Specific button while there are some buttons with same name { List <AutomationElement> lButtonAE = new List <AutomationElement>(); foreach (AutomationElement buttonAE in aec) { if (buttonAE.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == buttonName) { lButtonAE.Add(buttonAE); lButtonAE.Reverse(); } } if (index > lButtonAE.Count) { return("Button not found"); } else { buttonAction(lButtonAE[index - 1]); return("Done"); } } else { foreach (AutomationElement ae in aec) { if (isPartContainButtonName) { if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(buttonName) || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == buttonName) { buttonAction(ae); return("Done"); //must set return statement because once find the operated control, stop the whole function } } else { // Console.WriteLine("try to find button"); // Console.WriteLine(ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString()); if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == buttonName || ae.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty).ToString() == buttonName) { //Console.WriteLine("Find"); buttonAction(ae); return("Done"); } else { } } } } } } else { return("Button not found"); } return("OP End"); }
public static string GetButtonName(string WindowName) { ControlOp co = new ControlOp(ControlType.Button); return(co.getAllControlName(co, WindowName)); }
public static string GetCheckboxName(string WindowName) { ControlOp co = new ControlOp(ControlType.CheckBox); return(co.getAllControlName(co, WindowName)); }
public static bool Exsit(string WindowName, string cName) { ControlOp co = new ControlOp(cName, ControlType.CheckBox); return(co.exist(co, WindowName)); }