Micro Focus QTP (UFT) Forums

Full Version: How to get total item in context menu?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have to automate context menu, in which we right click on an object and menu opens. How can we get all the childs from this menu?

Thanks,
I think QTP does not support context menu, but yes there can be different ways of handling operations on it using QTP.
If you can tell us the exact scenario what you want to do then may be I can help you.
I have a Tree view, and the root node of Tree View has context menu. In which we right click on node of tree view and menu opens, I have to get count of items in that menu. and also i have to get their labels. How can i do that?
Let me know, if my question is still not clear?
Hi,

I am not sure what you want to get. But may the next part of code will help you.

Open "My Documents" and run (<Item 5> in my case has submenu):

Code:
strWin = "My Documents"
Window("regexpwndtitle:="&strWin).Activate
wait 1
Window("regexpwndtitle:="&strWin).WinListView("regexpwndclass:=SysListView32").Select 0,micRightBtn
wait 2
Set oContMenu = Window("regexpwndtitle:="&strWin).WinObject("regexpwndclass:=SHELLDLL_DefView").WinMenu("menuobjtype:=3")
nCnt = oContMenu.GetItemProperty("", "SubMenuCount")
strMenu = oContMenu.GetItemProperty("<Item 5>", "Label") '// will return the menu string
Window("regexpwndtitle:="&strWin).WinListView("regexpwndclass:=SysListView32").Select 0,micRightBtn
bRes = oContMenu.GetItemProperty("<Item 5>", "HasSubMenu") '// if it has sub menu
wait 2
If bRes Then
    Window("regexpwndtitle:="&strWin).WinListView("regexpwndclass:=SysListView32").Select 0,micRightBtn
    wait 2
    oContMenu.Select strMenu
    nCnt2 = oContMenu.GetItemProperty("<Item 5>", "SubMenuCount")
    strMenu2 = oContMenu.GetItemProperty("<Item 5>;<Item 1>", "Label") '// will return the menu string
End If