private static void SelectItemInComboBox(AutomationElement element, String selectedItemName) { // Get the mapped item name. String itemName = TestDataInfrastructure.GetControlId(selectedItemName); // Set focus to ensure that the object is selected. element.SetFocus(); // Expand the ComboBox using ExpandCollapsePattern. ExpandCollapsePattern expandPattern = element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; expandPattern.Expand(); // get the desired automation element PropertyCondition itemNameCondition = new PropertyCondition(AutomationElement.NameProperty, itemName); PropertyCondition itemTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem); AndCondition itemCondition = new AndCondition(itemNameCondition, itemTypeCondition); AutomationElement item = element.FindFirst(TreeScope.Descendants, itemCondition); if (item != null) { // select combo box item ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select(); } }
protected override void Execute() { Condition controlCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, ControlId); var element = MainWindow.FindFirst(TreeScope.Descendants, controlCondition); if (element != null) { ExpandCollapsePattern expandPattern = null; try { expandPattern = (ExpandCollapsePattern)element.GetCurrentPattern(ExpandCollapsePattern.Pattern); expandPattern.Expand(); //expandPattern.Collapse(); } catch (Exception) { } AutomationElementCollection comboboxItems = element.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem)); foreach (AutomationElement automationElement in comboboxItems) { string elementValue = automationElement.Current.Name; if (!string.IsNullOrEmpty(elementValue) && elementValue.Trim().ToLower().Equals(this.Value.Trim().ToLower())) { //Finding the pattern which need to select SelectionItemPattern selectPattern = (SelectionItemPattern)automationElement.GetCurrentPattern(SelectionItemPattern.Pattern); selectPattern.Select(); } } } }
void ExpandAll(AutomationElement le, CheckType checkType) { if (le == null) { return; } string element = "\"" + Library.GetUISpyLook(le) + "\""; ExpandCollapsePattern ec = (ExpandCollapsePattern)le.GetCurrentPattern(ExpandCollapsePattern.Pattern); if (ec != null) { ec.Expand(); if (ec.Current.ExpandCollapseState.Equals(ExpandCollapseState.PartiallyExpanded)) { ec.Expand(); } if (ec.Current.ExpandCollapseState.Equals(ExpandCollapseState.Collapsed)) { ThrowMe(checkType, "Current ExpandCollapseState for (" + element + ") = " + ec.Current.ExpandCollapseState + " after call to Expand()"); } Comment("ExpandCollapseState = Expanded for " + element + " after call to Expand()"); } }
public static AutomationElement Expand(this AutomationElement parent, string name) { AutomationElement expando = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name)); if (expando == null) { throw new Exception("Expander '" + name + "' not found"); } for (int retries = 10; retries > 0; retries--) { ExpandCollapsePattern p = (ExpandCollapsePattern)expando.GetCurrentPattern(ExpandCollapsePattern.Pattern); p.Expand(); // either WPF or Automation is broken here because sometimes it does not expand. Thread.Sleep(250); if (p.Current.ExpandCollapseState == ExpandCollapseState.Expanded) { break; } else { Console.WriteLine("Expander '" + name + "' failed, trying again"); } } return(expando); }
public override void DoExecute() { AutomationElement a = UiElement.AutomationElement; Console.WriteLine(a.Current.AutomationId); ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; expandCollapsePattern.Expand(); var comboBoxEditItemCondition = new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxEditItem"); var listItems = a.FindAll(TreeScope.Subtree, comboBoxEditItemCondition);//It can only get one item in the list (the first one). var testItem = listItems[listItems.Count - 1]; int index1 = 0; int index = 0; foreach (AutomationElement item in listItems) { foreach (AutomationElement itemChild in item.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"))) { if (itemChild.Current.Name == Control.text) { //testItem= } } index++; } (testItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select(); expandCollapsePattern.Collapse(); }
private static void executePattern(AutomationElement subject, AutomationPattern inPattern) { switch (inPattern.ProgrammaticName) { case "InvokePatternIdentifiers.Pattern": { InvokePattern invoke = (InvokePattern)subject.GetCurrentPattern(InvokePattern.Pattern); invoke.Invoke(); break; } case "SelectionItemPatternIdentifiers.Pattern": { SelectionItemPattern select = (SelectionItemPattern)subject.GetCurrentPattern(SelectionItemPattern.Pattern); select.Select(); break; } case "TogglePatternIdentifiers.Pattern": { TogglePattern toggle = (TogglePattern)subject.GetCurrentPattern(TogglePattern.Pattern); toggle.Toggle(); break; } case "ExpandCollapsePatternIdentifiers.Pattern": { ExpandCollapsePattern exColPat = (ExpandCollapsePattern)subject.GetCurrentPattern(ExpandCollapsePattern.Pattern); exColPat.Expand(); break; } } }
/// <summary> /// Check out a document on opening word /// </summary> /// <param name="name">Document name</param> public static void CheckOutOnOpeningWord(string name) { AutomationElement docOnline = GetWordOnlineWindow(name); Condition File_Tab = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "File Tab")); WaitForElement(docOnline, File_Tab, TreeScope.Descendants); AutomationElement item_File = docOnline.FindFirst(TreeScope.Descendants, File_Tab); InvokePattern Pattern_File = (InvokePattern)item_File.GetCurrentPattern(InvokePattern.Pattern); Pattern_File.Invoke(); Condition Group_Info = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, "Info")); AutomationElement item_Info = docOnline.FindFirst(TreeScope.Descendants, Group_Info); Condition Con_ManageVersions = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Manage Document")); AutomationElement item_ManageVersions = item_Info.FindFirst(TreeScope.Descendants, Con_ManageVersions); ExpandCollapsePattern Pattern_ManageVersions = (ExpandCollapsePattern)item_ManageVersions.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern); Pattern_ManageVersions.Expand(); Condition Con_CheckOut = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Check Out")); AutomationElement item_CheckOut = item_Info.FindFirst(TreeScope.Descendants, Con_CheckOut); InvokePattern Pattern_CheckOut = (InvokePattern)item_CheckOut.GetCurrentPattern(InvokePattern.Pattern); Pattern_CheckOut.Invoke(); Thread.Sleep(8000); Condition File_Save = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Save")); AutomationElement item_Save = docOnline.FindFirst(TreeScope.Descendants, File_Save); InvokePattern Pattern_Save = (InvokePattern)item_Save.GetCurrentPattern(InvokePattern.Pattern); Pattern_Save.Invoke(); Thread.Sleep(2000); }
public static void SetSelectedComboBoxItem(AutomationElement comboBox, string item) { AutomationPattern automationPatternFromElement = GetSpecifiedPattern(comboBox, "ExpandCollapsePatternIdentifiers.Pattern"); ExpandCollapsePattern expandCollapsePattern = comboBox.GetCurrentPattern(automationPatternFromElement) as ExpandCollapsePattern; expandCollapsePattern.Expand(); expandCollapsePattern.Collapse(); AutomationElement listItem = comboBox.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, item)); automationPatternFromElement = GetSpecifiedPattern(listItem, "SelectionItemPatternIdentifiers.Pattern"); SelectionItemPattern selectionItemPattern = listItem.GetCurrentPattern(automationPatternFromElement) as SelectionItemPattern; selectionItemPattern.Select(); }
static void Main(string[] args) { var pInfo = new ProcessStartInfo("notepad"); var p = Process.Start(pInfo); p.WaitForInputIdle(); AutomationElement installerEditorForm = AutomationElement.FromHandle(p.MainWindowHandle); // menus AutomationElementCollection menuBars = installerEditorForm.FindAll(TreeScope.Children, new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.MenuBar)); var mainMenuItem = menuBars[0]; AutomationElementCollection menus = mainMenuItem.FindAll(TreeScope.Children, new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.MenuItem)); var fileMenuItem = menus[0]; ExpandCollapsePattern fileMenuItemOpenPattern = (ExpandCollapsePattern)fileMenuItem.GetCurrentPattern( ExpandCollapsePattern.Pattern); fileMenuItemOpenPattern.Expand(); AutomationElement fileMenuItemNew = fileMenuItem.FindFirst(TreeScope.Children, new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "New"))); Console.Read(); }
//</Snippet1102> ///-------------------------------------------------------------------- /// <summary> /// Handles the ExpandCollapse click event. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">Event arguments.</param> ///-------------------------------------------------------------------- private void ExpandCollapse_Click(object sender, RoutedEventArgs e) { Button clientButton = sender as Button; ExpandCollapsePattern ec = clientButton.Tag as ExpandCollapsePattern; if (ec == null) { return; } ExpandCollapseState currentState = ec.Current.ExpandCollapseState; try { if ((currentState == ExpandCollapseState.Collapsed) || (currentState == ExpandCollapseState.PartiallyExpanded)) { ec.Expand(); statusText.Text = "TreeItem expanded."; } else if (currentState == ExpandCollapseState.Expanded) { ec.Collapse(); statusText.Text = "TreeItem collapsed."; } } catch (InvalidOperationException) { // The current state of the element is LeafNode. Output("Unable to expand or collapse the element."); } }
private bool ExpandListIfNeeded(out ExpandCollapsePattern expandCollapsePattern) { if (!IsExpansionRequired || !Enabled) { expandCollapsePattern = null; return(false); } if (!TryGetExpandCollapsePattern(out expandCollapsePattern)) { return(false); } var expansionState = expandCollapsePattern.Current.ExpandCollapseState; if (expansionState != ExpandCollapseState.Collapsed) { return(false); } expandCollapsePattern.Expand(); Thread.Sleep(50); return(true); }
private ExpandCollapsePattern FindMenu(CalculatorMenu menu) { AutomationElement menuElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu.ToString())); ExpandCollapsePattern expPattern = menuElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; return(expPattern); }
public static void Expand(this AutomationElement root) { Thread.Sleep(100); ExpandCollapsePattern p = (ExpandCollapsePattern)root.GetCurrentPattern(ExpandCollapsePattern.Pattern); p.Expand(); }
private static void ExpandMenuItem(AutomationElement aeMenu) { ExpandCollapsePattern itemOpenPattern = aeMenu.GetCurrentPattern( ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; itemOpenPattern.Expand(); }
//private bool SelectDropDownItem(this AutomationElement comboBoxElement, string item) { // bool itemFound = false; // AutomationElement elementList; // CacheRequest cacheRequest = new CacheRequest(); // cacheRequest.Add(AutomationElement.NameProperty); // cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children; // using (cacheRequest.Activate()) { // // Load the list element and cache the specified properties for its descendants. // Condition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List); // elementList = comboBoxElement.FindFirst(TreeScope.Children, cond); // } // //Loop thru and find the actual ListItem // foreach (AutomationElement child in elementList.CachedChildren) // if (child.Cached.Name == item) { // SelectionItemPattern select = (SelectionItemPattern)child.GetCurrentPattern(SelectionItemPattern.Pattern); // select.Select(); // itemFound = true; // break; // } // return itemFound; //} public void ComboSelect_UsingUIAutomation(string MainWindowName, string ComboBox_AutomationID, string SelectItemText) { AutomationElement desktop = AutomationElement.RootElement; AutomationElement MainWindow = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, MainWindowName)); AutomationElement cboBox, cboItem; cboBox = MainWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, ComboBox_AutomationID)); //Click the combo box to expand the items ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)cboBox.GetCurrentPattern(ExpandCollapsePattern.Pattern); expandPattern.Expand(); //Search the item then click the item cboItem = cboBox.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, SelectItemText)); SelectionItemPattern itemSelect = (SelectionItemPattern)cboItem.GetCurrentPattern(SelectionItemPattern.Pattern); try { itemSelect.Select(); } catch (Exception) { //Ignore this error, bcz some window will wait until the some action has been carried, } //InvokePattern click = (InvokePattern)cboItem.GetCurrentPattern(InvokePattern.Pattern); //click.Invoke(); //click = null; //Release the memory MainWindow = null; //childWindow = null; desktop = null; GC.Collect(); }
public static AutomationElement SetComboBox(this AutomationElement parent, string name, string value) { AutomationElement box = parent.FindFirstWithRetries(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, name)); if (box == null) { throw new Exception("ComboBox '" + name + "' not found"); } if (!box.Current.IsEnabled) { throw new Exception("ComboBox '" + name + "' is not enabled"); } ExpandCollapsePattern p = (ExpandCollapsePattern)box.GetCurrentPattern(ExpandCollapsePattern.Pattern); p.Expand(); Thread.Sleep(250); AutomationElement item = box.FindFirstWithRetries(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.NameProperty, value), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem))); if (item == null) { throw new Exception("ComboBoxItem '" + value + "' not found in combo box '" + name + "'"); } SelectionItemPattern si = (SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern); si.Select(); p.Collapse(); return(box); }
/// <summary> /// Merge document with conflict /// </summary> /// <param name="filename">file name</param> public static void WordConflictMerge(string filename) { var desktop = AutomationElement.RootElement; //Microsoft.Office.Interop.Word.Application wordToOpen = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); //Microsoft.Office.Interop.Word.Document oDocument = (Microsoft.Office.Interop.Word.Document)wordToOpen.ActiveDocument; Condition Con_Document = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new OrCondition(new PropertyCondition(AutomationElement.NameProperty, filename + ".docx - Word"), new PropertyCondition(AutomationElement.NameProperty, filename + " - Word"))); AutomationElement item_Document = desktop.FindFirst(TreeScope.Children, Con_Document); Condition Con_Resolve = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Resolve")); AutomationElement item_Resolve = WaitForElement(item_Document, Con_Resolve, TreeScope.Descendants, false); item_Resolve = item_Document.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Resolve")); InvokePattern Pattern_Resolve = (InvokePattern)item_Resolve.GetCurrentPattern(InvokePattern.Pattern); Pattern_Resolve.Invoke(); Condition Con_AcceptMyChange = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.SplitButton), new PropertyCondition(AutomationElement.NameProperty, "Accept My Change")); AutomationElement item_AcceptMyChange = WaitForElement(item_Document, Con_AcceptMyChange, TreeScope.Descendants, false); ExpandCollapsePattern Pattern_AcceptMyChange = (ExpandCollapsePattern)item_AcceptMyChange.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern); Pattern_AcceptMyChange.Expand(); Condition Con_AcceptAll = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Accept All Conflicting Changes in Document")); AutomationElement item_AcceptAll = WaitForElement(item_Document, Con_AcceptAll, TreeScope.Descendants, false); InvokePattern Pattern_AcceptAll = (InvokePattern)item_AcceptAll.GetCurrentPattern(InvokePattern.Pattern); Pattern_AcceptAll.Invoke(); Thread.Sleep(4000); Condition Con_SaveCloseView = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Save and Close View")); AutomationElement item_SaveCloseView = WaitForElement(item_Document, Con_SaveCloseView, TreeScope.Descendants, false); InvokePattern Pattern_SaveCloseView = (InvokePattern)item_SaveCloseView.GetCurrentPattern(InvokePattern.Pattern); Pattern_SaveCloseView.Invoke(); }
public void Select(string MenuPath) { AutomationElement curentmenuitem = _getmenuitembypath(this._condition.AutomationElement, MenuPath); if (curentmenuitem == null) { ControlSearcher.ThrowError(ErrorType.NotItemExistinthelist); } else { try { ExpandCollapsePattern mexpand = (ExpandCollapsePattern)curentmenuitem.GetCurrentPattern(ExpandCollapsePattern.Pattern); mexpand.Expand(); } catch { try { Point p = new Point(curentmenuitem.Current.BoundingRectangle.Left, curentmenuitem.Current.BoundingRectangle.Top); KeyInput.Click(KeyInput.MouseClickType.LClick, p); } catch { ControlSearcher.ThrowError(ErrorType.CannotPerformThisOperation); } } } }
public override void perform(ComponentPrx component, Ice.Current context__) { AutomationElement element = WGComponent.fromId(component.getId()); ExpandCollapsePattern patternMenu = element.GetCurrentPattern( ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; // Pattern is not available for this component if (patternMenu == null) { // TODO: Log message return; } ExpandCollapseState state = patternMenu.Current.ExpandCollapseState; if (state == ExpandCollapseState.Expanded) { patternMenu.Collapse(); } else if (state == ExpandCollapseState.PartiallyExpanded || state == ExpandCollapseState.Collapsed) { patternMenu.Expand(); } }
private void SetSelection(string option) { if ((comboBoxElement != null) && (comboBoxElement.Current.IsEnabled)) { AutomationElement sel = null; ExpandCollapsePattern expandPattern = (ExpandCollapsePattern)comboBoxElement .GetCurrentPattern( ExpandCollapsePattern.Pattern); expandPattern.Expand(); CacheRequest cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.TreeScope = TreeScope.Element | TreeScope.Children; AutomationElement comboboxItems = comboBoxElement.GetUpdatedCache( cacheRequest); foreach (AutomationElement item in comboboxItems.CachedChildren) { if (item.Current.Name == "") { CacheRequest cacheRequest2 = new CacheRequest(); cacheRequest2.Add(AutomationElement.NameProperty); cacheRequest2.TreeScope = TreeScope.Element | TreeScope.Children; AutomationElement comboboxItems2 = item.GetUpdatedCache(cacheRequest); foreach (AutomationElement item2 in comboboxItems2.CachedChildren) { if (item2.Current.Name == option) { sel = item2; } } } } if (sel != null) { SelectionItemPattern select = (SelectionItemPattern)sel.GetCurrentPattern( SelectionItemPattern.Pattern); select.Select(); } expandPattern.Collapse(); } SetForegroundWindow(this.Handle); }
private void ClickFileMenuItem() { fileMenuItem = GetElement("menuItemFile"); Console.WriteLine("Clicking file on menu"); ExpandCollapsePattern clickFile = (ExpandCollapsePattern)fileMenuItem.GetCurrentPattern(ExpandCollapsePattern.Pattern); clickFile.Expand(); }
/// <summary> /// Expands the specified control. /// </summary> /// <param name="control">The UI Automation element</param> /// <returns> /// 0 if no problems encountered, -1 if InvalidOperationException is raised /// </returns> internal static int Expand(AutomationElement control) { ExpandCollapsePattern pat = (ExpandCollapsePattern)CommonUIAPatternHelpers.CheckPatternSupport(ExpandCollapsePattern.Pattern, control); control.SetFocus(); pat.Expand(); return(0); }
public static bool Collapse(AutomationElement item) { ExpandCollapsePattern pattern = item.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; pattern.Collapse(); return(true); }
public static void Collapse(this AutomationElement expandControl) { //check if the buttonControl is indeed a handle to a button-based control ExpandCollapsePattern expColPattern = ValidateExpandCollapseControl(expandControl); //Collapse expColPattern.Collapse(); }
private void GetLooksListFromPro7UI() { cboLooks.Items.Clear(); // Setup a condition and find the first menu named "Screens" Condition conditionScreensMenu = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Screens") ); AutomationElement aeScreensMenu = aeProPresenter.FindFirst(TreeScope.Descendants, conditionScreensMenu); // If Screens menu is not currently expanded then expand it - as WPF menuItems need to be expanded to explore them. ExpandCollapsePattern expandPattern = aeScreensMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; if (expandPattern.Current.ExpandCollapseState != ExpandCollapseState.Expanded) { expandPattern.Expand(); } // Let's get all the sub menuitems of the Screens menu... AutomationElementCollection aecScreensMenuItems = aeScreensMenu.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem)); // If UI changes in design, this code will break - it assumes Looks menu is at index 2 of the screens menu items. // The third sub menuitem of the Screens menu is the Live:Look menu (well, at least in Pro7.4.1 - this may change in future) AutomationElement liveMenu = aecScreensMenuItems[2]; // Grab the name of the current look String currentLookName = liveMenu.FindAll(TreeScope.Descendants, Condition.TrueCondition)[1].Current.Name; // If Live:Look menu is not currently expanded then expand it - as WPF menuItems need to be expanded to explore them. ExpandCollapsePattern expandPattern2 = liveMenu.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; if (expandPattern2.Current.ExpandCollapseState != ExpandCollapseState.Expanded) { expandPattern2.Expand(); } // Let's get all the sub menuitems of the Live:Look menu (this is where we finally get a list of the looks) aeLiveMenuItems = liveMenu.FindAll(TreeScope.Children, Condition.TrueCondition); // - to get names, grab child textblock of each menuItem) AutomationElementCollection aeLiveMenuItems2 = aeLiveMenuItems[0].FindAll(TreeScope.Descendants, Condition.TrueCondition); // Add each look to a list....(ready to invoke later when clicked) foreach (AutomationElement liveMenuItem in aeLiveMenuItems) { this.cboLooks.Items.Add(liveMenuItem.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)).Current.Name); } if (currentLookName.Length > 0) { this.cboLooks.SelectedItem = currentLookName; } // Collapse Menu - we are done exploring.. expandPattern2.Collapse(); expandPattern.Collapse(); }
/// <summary> /// Expands the selected item. The item must support the expand/collapse pattern. /// </summary> /// <param name="node"></param> internal static void EnsureExpanded(AutomationElement node) { ExpandCollapsePattern pat = (ExpandCollapsePattern)node.GetCurrentPattern(ExpandCollapsePattern.Pattern); if (pat.Current.ExpandCollapseState == ExpandCollapseState.Collapsed) { pat.Expand(); } }
public static void Expand(AutomationElement element) { ExpandCollapsePattern currentPattern = AutomationPatternHelper.GetExpandCollapsePattern(element); if (currentPattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed) { currentPattern.Expand(); } }
/// <summary> /// Create a new automation helper for the pattern /// </summary> /// <param name="element">The automation element to wrap</param> public ExpandableElement(AutomationElement element) { base.element = element; pattern = Element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; if (pattern == null) { throw new ArgumentException("Helper must represent a selectable item"); } }
/// <summary> /// Collapses the selected item. The item must support the expand/collapse pattern. /// </summary> /// <param name="node"></param> public static void Collapse(AutomationElement node) { CheckNullElement(node); ExpandCollapsePattern pat = (ExpandCollapsePattern)node.GetCurrentPattern(ExpandCollapsePattern.Pattern); if (pat.Current.ExpandCollapseState != ExpandCollapseState.Collapsed) { pat.Collapse(); } }
public override void DoExecute() { AutomationElement a = UiElement.AutomationElement; ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; expandCollapsePattern.Expand(); var cbxEditItems = UiElement.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxEditItem")); switch (PlaybackObject.action) { case "SetText": try { var Editor = a.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "PART_Editor")); ((ValuePattern)Editor.GetCurrentPattern(ValuePattern.Pattern)).SetValue(PlaybackObject.text); expandCollapsePattern.Collapse(); Result = true; } catch (Exception) { Result = false; //throw; } break; case "Select": try { if (cbxEditItems[PlaybackObject.itemIndex].AutomationElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "CheckEdit")) != null) { var checkBox = cbxEditItems[PlaybackObject.itemIndex].FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "CheckEdit")); checkBox.AsCheckBox().Click(); SendKeys.SendWait("{ENTER}"); } else { cbxEditItems[PlaybackObject.itemIndex].AutomationElement.SelectionItemPattern().Select(); expandCollapsePattern.Collapse(); } Result = true; } catch (Exception) { Result = false; //throw; } break; default: Result = false; break; } //expandCollapsePattern.Collapse(); }