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
mfoster711
Regular Contributor

Alex - Thanks for that tip, it helped me find the answer. The popup menu is a wndclass #32768 window that is a child of the process and sibling object to the main window. I am able to check if that window exists to determine if the menu is displaying.

mfoster711
Regular Contributor


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

That's how I do it in JScript!


That won't work because you will get a run time error when MainMenu does not exist. 

Thats not what happens for me?

 

I just tried it.

 

I have a mapped object, for the sake of argumnent, we'll call it:

 

Aliases.Part1.Part2.Part3 (not their real names, but it is 3 layers deep)

 

If I try:

 

x = Aliases.Part1.Part2.Part3.Exists

 

I simply get x = False (if the object is not present .... it's not. And neither are any of the parent objects.)

 

Of course, if it is there, I get True.

 

But it doesn't throw an error if it's not present. As I say, just tried it multiple time with the object (and it's parents) present or not. All worked as I would expect. Nothing caused an error to be thrown. I thought this was the point of the exists property? So you can check for the presence of things without having to worry about any error capturing or anything like that? If the object does not exists, it returns False by default.

 

I'm using C# script if that makes any difference?

cancel
Showing results for 
Search instead for 
Did you mean: