Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
9 years ago

Check PopupMenu exists

How do I check if a popup menu exists before I try to interact with it? 

 

The following code works as long as the PopupMenu exists. If it doesn't, I get a run time error on the second line.

 

CurrField.Click x,y
Call CurrField.PopupMenu.Click("Sort|Descending")

I tried adding a check for CurrField.PopupMenu.Exists or CurrField.PopupMenu = Null and both of these cause run time errors also.

  • AlexKaras's avatar
    AlexKaras
    9 years ago

    Hi,

     

    Ah, I see. Property will be of no use for you.

    What you should do in this case:

    1) Open Object Spy in TestComplete and switch it to Point-and-Fix mode;

    2) (Right-)click on the control so that the popup menu is opened;

    3) Hover popup menu with the mouse and wait until it is recognized by Object Spy;

    4) Fix the captured object in the Object Spy (Ctrl-Shift-A shortcut if I remember correctly);

    5) Copy the identification code from Object Spy into your test code, adjust and use accordingly.

     

    (It is a usual thing that popup menu is a separate standalone object that is a child of either tested application process or main window.)

  • Don's avatar
    Don
    Contributor

    There's no way of checking to see if a window exists unless you manually verify all the steps. The pop up windows are something that should be in the design documentation.

     

    You can also see if a window exists by going to a browser and clicking F12 for development mode. Then you would just have to dig through to see if there are any windows and find your matching window if it exists.

     

    This is how I find pop up windows and implement them using the xpath.

    • Don's avatar
      Don
      Contributor

      Sorry I meant to say pop up menu but I accidently put widow. But the logic still applies.

      • mfoster711's avatar
        mfoster711
        Regular Contributor

        I am working with a Desktop application, not a browser.

  • detached31's avatar
    detached31
    Occasional Contributor

    I'm late to the discussion, but I just had the case, around TestComplete/Execute 15.57.

    I wanted to test wnd.PopupMenu for null, before calling Click() on it.

    It seems that getting the PopupMenu property is not exactly a passive readonly code; I guess it's doing something to check the popup window. When calling PopupMenu twice, once to check whether it's null, and then again to call Click() on it, the second value was always null.

    What worked for me is this (JScript):

    var mnu = wnd.PopupMenu;
    if (mnu != null) { mnu.Click("xxx"); }
    else { Log.Error("null popup"); }