Get menu and submenu names in the Windows application​ using UFT

UFT works very well with Windows as well as web applications. To get menu and submenu names in the Windows application, we can create a function like below using VBScript.

The object names are just for reference purposes and are not to be taken exactly.

All the objects of the Windows application such as WinMenu etc have to be rescanned using Object Spy and added to the Object Repository.

Example code to get Menu and submenu names in Windows application
Set obj_Menu = VbWindow("frm_main").WinMenu("Menu")
GetNamesRec "", obj_Menu

' Open All Menus and Sub-Menus and Write the Menu Names in the Results
Function GetNamesRec(itemPath, menuObj)
ret = 0
lbl = menuObj.GetItemProperty(itemPath, "Label")
Reporter.ReportEvent 0, itemPath & " label", lbl
ret = menuObj.GetItemProperty(itemPath, "HasSubMenu")
If ret Then
cnt = menuObj.GetItemProperty(itemPath, "SubMenuCount")
Reporter.ReportEvent 0, itemPath & " sub-menu items", cnt
For n = 1 To cnt
Path = menuObj.BuildMenuPath(itemPath, n)
GetNamesRec Path, menuObj
Next
End If
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.