Count number of items in a popupmenu TestPartner

Count number of items in a popupmenu TestPartner

The following VBA test script counts the number of items in a popupmenu.  The example uses a Notepad window and the menu that appears when you right click on the window title bar.  A message box displays the number of items in the menu, then displays each menu item, and checks if the item is enabled.

Sub Main()

 

   Window("Untitled - Notepad Window").Attach

   Window.Click 200, -30, tpMouseRight

   Pause 1

   Set w = Window("Application=NOTEPAD.EXE Caption=''")

   Set m = w.GetMenu(tpMenu)

 

   'Count the menu items

   MenuItemCount = m.Count

   MsgBox MenuItemCount & " items"

   'Loop through the menu to get each item

   For i = 1 To MenuItemCount

   Window.Click 200, -30, tpMouseRight

   Set w = Window("Application=NOTEPAD.EXE Caption=''")

   Set m = w.GetMenu(tpMenu)

   'Get the menu item

     Set mi = m.GetItem(i)

     MsgBox mi

    

   'Check if the item is enabled

     MsgBox mi.Enabled

     Next

 

End Sub

 Support incident 2655974

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Version history
Revision #:
1 of 1
Last update:
‎2013-10-23 12:12
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.