Ask a Question

Check PopupMenu exists

SOLVED
mfoster711
Regular Contributor

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.

12 REPLIES 12
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
Contributor

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

mfoster711
Regular Contributor

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

"CurrField.PopupMenu.Exists"

 

Should work? The whole point of the Exists property is so to do exactly this. It shouldn't be throwing an error.

 

Are you sure the parent objects all exist at this point? If "CurrField" does not exist, that may be object actually causing the error (or anything else further up the tree). I use "Exists" to check the presence (or lack of) on transient popup menus all the time without any problems.

Exists does not work for PopupMenu. I added the following and verified the CurrField exists.

If CurrField.Exists Then
    log.message "CurrField exists"
End If
If CurrField.PopopMenu.Exists Then
    log.message "PopupMenu exists"
End If

I get a runtime error on the line that checks if CurrField.PopupMenu.Exists. The error log states "Cannot obtain the popup menu".

@mfoster711

Hi,

 

When you are trying to access some property or some method of some object, TestComplete first tries to get this object and fails if the object does not exist. This is the reason why the line

CurrField.PopupMenu.Exists

fails if popup menu does not exist.

 

The proper way in this case is to try to get the object first and if this succeeds proceed further.

E.g. (VBScript pseudocode):

Set obj = CurrField.WaitChild("PopupMenu", 5000)

If (Not obj.Exists) Then

  Call Log.Warning("Popup was not found")

Else

  Call CurrField.PopupMenu.Click("Sort|Descending")

End If

 

 

CurrField.PopupMenu.Click("Sort|Descending")

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
mfoster711
Regular Contributor

I tried that but it does not work either. It always says the obj does not exists it when it does exist.

 

I believe this is because the PopupMenu is not a child of CurrField, it is a property of CurrField. CurrField does not have any child objects.

if (!Object.MainMenu.Items("Menu").SubMenu.Items("Submenu").Exists) {
    Log.Warning("Object doesn't exists");
}

That's how I do it in JScript!

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.)

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
cancel
Showing results for 
Search instead for 
Did you mean: