private int HandleSubMenu(AutomationElement childHandle, AutomationElement firstObjHandle, ref ArrayList menuList) { string matchedKey = null; Hashtable objectHT = new Hashtable(); try { menuList.Clear(); utils.InternalGetObjectList(childHandle, ref menuList, ref objectHT, ref matchedKey); if (menuList.Count > 0) { // Set it back to old state, // else the menu selection left there utils.InternalClick(firstObjHandle); // Don't process the last item return(1); } else { LogMessage("menuList.Count <= 0: " + menuList.Count); } } catch (Exception ex) { LogMessage(ex); } finally { objectHT = null; } return(0); }
private bool SelectListItem(AutomationElement element, String itemText, bool verify = false) { if (element == null || String.IsNullOrEmpty(itemText)) { throw new XmlRpcFaultException(123, "Argument cannot be null or empty."); } element.SetFocus(); LogMessage("SelectListItem Element: " + element.Current.Name + " - Type: " + element.Current.ControlType.ProgrammaticName); Object pattern = null; AutomationElement elementItem; try { utils.InternalWait(1); String enterKeys = itemText; if (enterKeys.StartsWith("*")) { enterKeys = enterKeys.Remove(0, 1); } Keyboard kb = new Keyboard(utils); kb.GenerateKeyEvent(enterKeys); elementItem = utils.GetObjectHandle(element, itemText); if (elementItem != null) { LogMessage(elementItem.Current.Name + " : " + elementItem.Current.ControlType.ProgrammaticName); if (verify) { bool status = false; if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { status = ((SelectionItemPattern)pattern).Current.IsSelected; } if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); element.SetFocus(); ((ExpandCollapsePattern)pattern).Collapse(); } return(status); } if (elementItem.TryGetCurrentPattern(ScrollItemPattern.Pattern, out pattern)) { LogMessage("ScrollItemPattern"); ((ScrollItemPattern)pattern).ScrollIntoView(); } if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { LogMessage("SelectionItemPattern"); //((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 return(utils.InternalClick(elementItem)); } else if (elementItem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); ((ExpandCollapsePattern)pattern).Expand(); element.SetFocus(); return(true); } else { throw new XmlRpcFaultException(123, "Unsupported pattern."); } } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { pattern = null; elementItem = null; } throw new XmlRpcFaultException(123, "Unable to find item in the list: " + itemText); }
public int SelectRow(String windowName, String objName, String text, bool partialMatch = false) { if (String.IsNullOrEmpty(text)) { throw new XmlRpcFaultException(123, "Argument cannot be empty."); } Object pattern; ControlType[] type; AutomationElement elementItem; AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } try { childHandle.SetFocus(); if (partialMatch) { text += "*"; } type = new ControlType[2] { ControlType.TreeItem, ControlType.ListItem }; elementItem = utils.GetObjectHandle(childHandle, text, type, true); if (elementItem != null) { elementItem.SetFocus(); LogMessage(elementItem.Current.Name + " : " + elementItem.Current.ControlType.ProgrammaticName); if (elementItem.TryGetCurrentPattern( SelectionItemPattern.Pattern, out pattern)) { LogMessage("SelectionItemPattern"); //((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(elementItem); return(1); } else if (elementItem.TryGetCurrentPattern( ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); ((ExpandCollapsePattern)pattern).Expand(); return(1); } else { throw new XmlRpcFaultException(123, "Unsupported pattern."); } } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { type = null; pattern = null; elementItem = childHandle = null; } throw new XmlRpcFaultException(123, "Unable to find the item in list: " + text); }
public int MouseLeftClick(String windowName, String objName) { Object pattern = null; AutomationElement childHandle; try { childHandle = utils.GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { throw new XmlRpcFaultException(123, "Object state is disabled"); } try { childHandle.SetFocus(); } catch (Exception ex) { // Have noticed exception with // maximize / minimize button LogMessage(ex); } if (childHandle.Current.ControlType == ControlType.Pane) { // NOTE: Work around, as the pane doesn't seem to work // with any actions. Noticed this window, when Windows // Security Warning dialog pop's up utils.InternalClick(childHandle); return(1); } else if (childHandle.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) { if (childHandle.Current.ControlType == ControlType.Menu || childHandle.Current.ControlType == ControlType.MenuBar || childHandle.Current.ControlType == ControlType.MenuItem || childHandle.Current.ControlType == ControlType.ListItem) { //((InvokePattern)invokePattern).Invoke(); // 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(childHandle); } else { try { ((InvokePattern)pattern).Invoke(); } catch (Exception ex) { LogMessage(ex); // Have noticed exception with // maximize / minimize button utils.InternalClick(childHandle); } } return(1); } else if (childHandle.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { ((SelectionItemPattern)pattern).Select(); return(1); } else { utils.InternalClick(childHandle); return(1); } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { pattern = null; childHandle = null; } throw new XmlRpcFaultException(123, "Unable to perform action"); }
public int Click(String windowName, String objName) { ControlType[] type = new ControlType[11] { ControlType.Button, ControlType.CheckBox, ControlType.RadioButton, ControlType.SplitButton, ControlType.Menu, ControlType.ListItem, ControlType.MenuItem, ControlType.MenuBar, ControlType.Pane, ControlType.Hyperlink, ControlType.ToolBar }; Object pattern = null; AutomationElement childHandle; try { childHandle = GetObjectHandle(windowName, objName, type); if (!utils.IsEnabled(childHandle)) { throw new XmlRpcFaultException(123, "Object state is disabled"); } try { childHandle.SetFocus(); } catch (Exception ex) { // Have noticed exception with // maximize / minimize button LogMessage(ex); } if (childHandle.Current.ControlType == ControlType.Pane) { // NOTE: Work around, as the pane doesn't seem to work // with any actions. Noticed this window, when Windows // Security Warning dialog pop's up utils.InternalClick(childHandle); return(1); } else if (childHandle.TryGetCurrentPattern(InvokePattern.Pattern, out pattern)) { if (childHandle.Current.ControlType == ControlType.Menu || childHandle.Current.ControlType == ControlType.MenuBar || childHandle.Current.ControlType == ControlType.MenuItem || childHandle.Current.ControlType == ControlType.ListItem) { //((InvokePattern)invokePattern).Invoke(); // 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(childHandle); } else { try { ((InvokePattern)pattern).Invoke(); } catch (Exception ex) { LogMessage(ex); // Have noticed exception with // maximize / minimize button utils.InternalClick(childHandle); } } return(1); } else if (childHandle.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { ((SelectionItemPattern)pattern).Select(); return(1); } else if (childHandle.TryGetCurrentPattern(ValuePattern.Pattern, out pattern) && childHandle.Current.ControlType == ControlType.ListItem) { // Fixed based on "Windows Security" dialog // On clicking "Use another account" // Its ListItem and has only ValuePattern utils.InternalClick(childHandle); return(1); } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { type = null; pattern = null; childHandle = null; } throw new XmlRpcFaultException(123, "Unable to perform action"); }
public int SelectTab(String windowName, String objName, String tabName) { if (String.IsNullOrEmpty(tabName)) { throw new XmlRpcFaultException(123, "Argument cannot be empty."); } AutomationElement elementItem; AutomationElement childHandle = GetObjectHandle(windowName, objName); if (!utils.IsEnabled(childHandle)) { childHandle = null; throw new XmlRpcFaultException(123, "Object state is disabled"); } Object pattern; try { try { childHandle.SetFocus(); } catch (System.Runtime.InteropServices.COMException ex) { // Noticed this with Notepad LogMessage("Error HRESULT E_FAIL has been" + " returned from a call to a COM component."); LogMessage(ex.StackTrace); } elementItem = utils.GetObjectHandle(childHandle, tabName); if (elementItem != null) { LogMessage(elementItem.Current.Name + " : " + elementItem.Current.ControlType.ProgrammaticName); if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pattern)) { LogMessage("SelectionItemPattern"); //((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(elementItem); return(1); } else if (elementItem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out pattern)) { LogMessage("ExpandCollapsePattern"); ((ExpandCollapsePattern)pattern).Expand(); return(1); } else { throw new XmlRpcFaultException(123, "Unsupported pattern."); } } } catch (Exception ex) { LogMessage(ex); if (ex is XmlRpcFaultException) { throw; } else { throw new XmlRpcFaultException(123, "Unhandled exception: " + ex.Message); } } finally { pattern = null; childHandle = null; } throw new XmlRpcFaultException(123, "Unable to find the item in tab list: " + tabName); }