how to select an item from right click menu

Apr 4, 2012 at 8:56 AM

Hi,

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"));

label1.RightClick();

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 11:16 AM

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"));
label1.RightClick();

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

menu1.Click();
but the third line is throwing "Null reference found" exception.
Apr 10, 2012 at 7: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 5: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 6: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"));
                buttonTrophy.Click();

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

May 10, 2012 at 6: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 8:17 AM
Edited May 11, 2012 at 8:22 AM

WPF, Silverlight or WinForm?

 

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

 

Throndorin

May 11, 2012 at 8:38 AM

hi,

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 :(   */

buttonElement.SetFocus();
SendKeys.SendWait("{ENTER}");


 

May 11, 2012 at 8:16 PM
Edited May 11, 2012 at 8: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"));

menu.Click();