This project is read-only.

How to get list of popup menu entries

Jun 11, 2009 at 2:01 PM



is there an easy way to get a list with all menu entries(top level)

and than a list with all menu entries of a sub menu.

Window window;

window.PopUp.Items does not exist. and

window.PopUp.Item select only the menu or submenu item.


any ideas?




Jun 15, 2009 at 11:42 AM

Here the way I actually use it:


public static AutomationElementCollection GetContextMenuEntriesOnRootMenu(Window window)

      //At this point your context menu is open.
      //Root element is the Visual Studio Window
      AutomationElement aeContextMenuContainer = window.AutomationElement;
      Condition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Menu);
      //get the menu
      var aeContextMenu = aeContextMenuContainer.FindFirst(TreeScope.Children, cond);
      //get the children
      AutomationElementCollection aeCol = aeContextMenu.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem));
      //Assert.AreEqual( entries.Count, aeCol.Count, "There are not the correct count of menu entries in the list" );

      return aeCol;

Jun 15, 2009 at 5:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.