Showing results for 
Search instead for 
Did you mean: 

Accessing Sub Menu Items from Context Menu

New Contributor

Accessing Sub Menu Items from Context Menu

This is my first question to the community.  I'm testing a WPF app with TC v12.60 and trying to access sub menu items from a context menu generated from a right-click on an object.


The context menus are as follows:

  • ContextMenu_Item1
  • ContextMenu_Item2
    • SubMenu1_Item1
      • SubMenu2_Item1
      • SubMenu2_Item2
    • SubMenu_Item2
  • etc.

The object that gets the right-click is in a ListView.  I generate the right click as follows:



I then access the contextmenu as follows:

contextmenu = Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot


I can navigate the submenus as follows:


# Hover mouse over a menu item at X,Y coordinate

contextmenu.HoverMouse(60, 100)


mouseX = Sys.Desktop.MouseX
mouseY = Sys.Desktop.MouseY
mouseX = mouseX + contextmenu.Width
submenu1 = Sys.ObjectFromPoint(mouseX, mouseY)
objectPoint = submenu1.ScreenToWindow(mouseX, mouseY)
submenu1.HoverMouse(objectPoint.X, objectPoint.Y)


mouseX = Sys.Desktop.MouseX
mouseY = Sys.Desktop.MouseY
mouseX = mouseX + submenu1.Width
submenu2 = Sys.ObjectFromPoint(mouseX, mouseY)
objectPoint = submenu2.ScreenToWindow(mouseX, mouseY)

submenu2.Click(objectPoint.X, objectPoint.Y)


This all works to click the menus, but I really want to access the menus by name instead of X,Y coordinates.  What is the best way to access the menu items by Header name or even by WPF Object name?




Community Hero

Re: Accessing Sub Menu Items from Context Menu

TestComplete provides access to popup menu objects. 


Have you tried below,

  1. Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.Click("<ITem name or Index>")
  2. Aliases.MyApp.HwndSource_mainWindow.mainWindow.tabControl1.listBoxDevices.Items(0).Popup.Clcik("<ITem name or Index>")
  3. If you are not able to find a solution with above two steps then try to record the action and see how TestComplete clicks. You will find a idea here.

Still you are not able to resolve prove some snapshots of Object properties etc.

Shankar R

LinkedIn | CG-VAK Software | Bitbucket |

“You must expect great things from you, before you can do them”

Extension Available

New Contributor

Re: Accessing Sub Menu Items from Context Menu

The recorded action converted to the following steps:

Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.Click(58, 105)
Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.Click(68, 11)
Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.Click(64, 15)


The image snapshots for each step above showed the correct submenu, but when run, all of the clicks occured in the first-level menu, not the submenus.  Additionally, these are still based on relative X,Y coordinates of the object.  I would like to access the menu items by name, header, or possibly even a tag in the WPF object.


The TC Click Action accepts X,Y coordinates, so name or index will not work as parameters there.


Others report success using FindChild, but I have not been able to get FindChild to return the menu item object.


The object returned by Point and Fix object:
Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1)


I'm thinking I need to poke around this object somehow.


New Contributor

Re: Accessing Sub Menu Items from Context Menu

Poking around the Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1) object has been enlightening, but I cannot figure out how to access the menu items by name.  I know this has been solved because I see other solutions.  Can someone help me understand what I'm working with?


While poking around, I did write the following snippet and received the following results.  Am I barking up the right tree or pursuing a futile course of action?  Can someone explain what these object are?




# Attempting to figure out how to access context menu items by names, so far unsuccessful
something = Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.FindAll(arrayproperties, arrayvalues, 100, True)
for x in range(len(something)):
  Log.Message("something[" + str(x) + "]" + something[x].ClrClassName + ", " + something[x].Name)
  somethingelse = something[x].FindAll(arrayproperties, arrayvalues, 100, True)
  for y in range(len(somethingelse)):
    Log.Message("somethingelse[" + str(y) + "]" + somethingelse[y].ClrClassName + ", " + somethingelse[y].Name)



something[0]PopupRoot, WPFObject("PopupRoot", "", 1)
somethingelse[0]PopupRoot, WPFObject("PopupRoot", "", 1)
somethingelse[1]Decorator, WPFObject("Decorator", "", 1)
somethingelse[2]NonLogicalAdornerDecorator, WPFObject("NonLogicalAdornerDecorator", "", 1)
somethingelse[3]AdornerLayer, WPFObject("AdornerLayer", "", 2)
somethingelse[4]AdornerLayer, WPFObject("AdornerLayer", "", 1)
something[1]Decorator, WPFObject("Decorator", "", 1)
somethingelse[0]Decorator, WPFObject("Decorator", "", 1)
somethingelse[1]NonLogicalAdornerDecorator, WPFObject("NonLogicalAdornerDecorator", "", 1)
somethingelse[2]AdornerLayer, WPFObject("AdornerLayer", "", 2)
somethingelse[3]AdornerLayer, WPFObject("AdornerLayer", "", 1)
something[2]NonLogicalAdornerDecorator, WPFObject("NonLogicalAdornerDecorator", "", 1)
somethingelse[0]NonLogicalAdornerDecorator, WPFObject("NonLogicalAdornerDecorator", "", 1)
somethingelse[1]AdornerLayer, WPFObject("AdornerLayer", "", 2)
somethingelse[2]AdornerLayer, WPFObject("AdornerLayer", "", 1)
something[3]AdornerLayer, WPFObject("AdornerLayer", "", 2)
somethingelse[0]AdornerLayer, WPFObject("AdornerLayer", "", 2)
something[4]AdornerLayer, WPFObject("AdornerLayer", "", 1)
somethingelse[0]AdornerLayer, WPFObject("AdornerLayer", "", 1)


New Contributor

Re: Accessing Sub Menu Items from Context Menu

No solution found on how to access context menu items by Name or by Header name.

New Here?
Join us and watch the welcome video:
Watch the new Interview