cancel
Showing results for 
Search instead for 
Did you mean: 

Exists property

SOLVED
Contributor

Exists property

I am trying to use the Exists property in javascript. I have an object that I would like to test to see if its still up on the screen or not. I write a loop that says 

 

while( testObject.Exists){

   wait(1)

}

 

Exept when the object is no longer on the screen it says it can't find the object. I get why it can't find the object because it doesn't exist on the screen. How can I test to see if an object is no longer on the screen and how is the Exists property suppose to work?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Exists property

I wouldn't use WaitProperty.  WaitProperty is a method assigned to an object.  So, when an object does not exist, calling that method will cause an error.

And that's the thing about the "Exists" property.  You can't call the "Exists" property of an object that does not exist.  If the object does not exist, it has no properties at all.

So...  if you want to see if an item is on screen, you would use WaitChild or WaitAliasChild or something like that from the parent object.

Let's say, for example, we have the following.

 

Aliases.MyApp

 

And after performing some sort of function I want to see if a form in that application exists, normally indicated by

 

Aliases.MyApp.MyForm

 

If it's a simple if-then, I'd do the following in JavaScript

 

if (Aliases.MyApp.WaitAliasChild('MyForm', 3000).Exists) {
    Log.Message('The form exists')
}
else {
    Log.Message('The form does not exist')
}

This code will wait up to a maximum of 3 seconds for the object to exist.  If it returns within 3 seconds, WaitAliasChild returns the actual object and Exists is true.  If the 3 second limit is exceeded, WaitAliasChild returns a "stub" object with ONLY the Exist property set to false

 

 


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
5 REPLIES 5
Community Hero
Community Hero

Re: Exists property

I wouldn't use WaitProperty.  WaitProperty is a method assigned to an object.  So, when an object does not exist, calling that method will cause an error.

And that's the thing about the "Exists" property.  You can't call the "Exists" property of an object that does not exist.  If the object does not exist, it has no properties at all.

So...  if you want to see if an item is on screen, you would use WaitChild or WaitAliasChild or something like that from the parent object.

Let's say, for example, we have the following.

 

Aliases.MyApp

 

And after performing some sort of function I want to see if a form in that application exists, normally indicated by

 

Aliases.MyApp.MyForm

 

If it's a simple if-then, I'd do the following in JavaScript

 

if (Aliases.MyApp.WaitAliasChild('MyForm', 3000).Exists) {
    Log.Message('The form exists')
}
else {
    Log.Message('The form does not exist')
}

This code will wait up to a maximum of 3 seconds for the object to exist.  If it returns within 3 seconds, WaitAliasChild returns the actual object and Exists is true.  If the 3 second limit is exceeded, WaitAliasChild returns a "stub" object with ONLY the Exist property set to false

 

 


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Contributor

Re: Exists property

Yeah, that does exactly what I want. Thanks. 

Contributor

Re: Exists property

Does this only work with Alias name mapping? Can this be done using the Sys.Process name mapping?

Community Hero

Re: Exists property

WaitAliasChild is specifically for NameMapping.

WaitVCLObject or WaitChild or WaitWPFObject... all are similar methods that perform a similar task.  Depending upon your needs, there should be a WaitNNN method for you.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Here?
Join us and watch the welcome video:
Top Kudoed Authors