Micro Focus QTP (UFT) Forums
how to check if selection in menu exists.. - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: how to check if selection in menu exists.. (/Thread-how-to-check-if-selection-in-menu-exists)



how to check if selection in menu exists.. - Anil Kumar - 10-14-2009

Hi,
I need to check to see if an "item/selection" in the menu exists. In the application I am testing, the menu item can be called different things and could be in different position.

What I want to do is something like this:
Code:
if "Tools;Loop Options..." exists in menu select it or else check if
"Tools;XML Element Options..." exists.. etc.

Is there any way of doing this?

Thanks in advance,
Anil


RE: how to check if selection in menu exists.. - jsknight1969 - 10-15-2009

The only way I have found to do this is select the item and trap the error that is returned if it's missing. It's a little messy, but it works...hopefully. I haven't had a reason to try this in an actual script, just tried a few things after reading your post.

Code:
on error resume next 'disable error trap
VbWindow("APP").WinMenu("Menu").Select("Tools;Loop Options...")
if Err.Number <> 0 then
  VbWindow("APP").WinMenu("Menu").Select("Tools;XML Loop Options...")
end if
on error goto 0 'reset error trapping

Another option might be to see if the window exist instead of the Err.Number. if the expected window does not exist then select the other menu option. Either way you have to bypass the error handler to continue.

GL.