This project is read-only.

how to select an item from right click menu

Apr 4, 2012 at 9:56 AM


i right clicked at a label and a menu appeared with 2 items. i want to select 1st item but unable to proceed

Label label1 = window1.Get<Label>(SearchCriteria.ByText("hello"));


what will be the control type of that right click menu and how can i proceed with selecting an item from that menu.

Apr 4, 2012 at 12:16 PM

I tried the hover mode of UI Spy and found the Automation id and control type as "Menu Item" for that item.

Label label1 = window1.Get<Label>(SearchCriteria.ByText("hello"));

Menu menu1 = window1.Get<Menu>(SearchCriteria.ByAutomationId("Item 318"));

but the third line is throwing "Null reference found" exception.
Apr 10, 2012 at 8:55 AM

Did u try getting the popup or modalwindow from the main window and then find what you are looking for?

Apr 11, 2012 at 6:42 PM
Label label1 = ...;
Window window = ...;

label1.RightClick(); PopUpMenu popUpMenu = window.Popup; Menu menu = popUpMenu.ItemBy(SearchCriteria.ByText(menuName)); menu.Click();
As noted above, you have to use the Popup property of the window to get the menu.
May 10, 2012 at 7:14 PM

I'm getting a NullReferenceException on the menu.Click() when running the following code (this is a context menu that displays when clicking the button):

White.Core.UIItems.Button buttonTrophy = mainWindow.Get(SearchCriteria.ByAutomationId("buttonTrop"));

White.Core.UIItems.MenuItems.PopUpMenu popupmenu = mainWindow.Popup;
White.Core.UIItems.MenuItems.Menu menu = popupmenu.ItemBy(SearchCriteria.ByText("Extract"));

May 10, 2012 at 7:33 PM

In addition to the problem above, it looks like this menu isn't displayed within the window in UISpy, and is instead displayed in its own pane called "menu" "Menu" (under "pane" ""(Desktop Window))

May 11, 2012 at 9:17 AM
Edited May 11, 2012 at 9:22 AM

WPF, Silverlight or WinForm?


Menu is MenuBar in White. Try to get MenuBar and from MenuBar the MenuItems (White Menu) .



May 11, 2012 at 9:38 AM


I know its not a white utility but this was very useful for me to find any UI Item on the window

AutomationElement root = AutomationElement.RootElement;
AutomationElement buttonElement = root.FindFirst(TreeScope.Descendants,
                                                             new PropertyCondition(AutomationElement.AutomationIdProperty, "ABCD"));
/* u can search by text or any other automation property, to find these properties u can use HOVER mode of UISpy */
/* i couldn't find any way to click buttonelement, so i 1st set focus and thn used system command :(   */



May 11, 2012 at 9:16 PM
Edited May 11, 2012 at 9:17 PM

It turns out the menu popup on the specific program wasn't displayed under the main window or modal windows.

The following code fixed it for me:

Window menubarWindow = program.GetWindow(SearchCriteria.ByText("Menu"), InitializeOption.NoCache);

Menu menu = menubarWindow.Get<Menu>(SearchCriteria.ByAutomationId("Item 260"));