Ask a Question

Exists property

SOLVED
4m4d3u5
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?

5 REPLIES 5
Marsha_R
Community Hero

You could use WaitProperty and wait for not-exists

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/waitpr...

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/waiting-state-changes.html


Marsha_R
[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
tristaanogre
Esteemed Contributor

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
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available

Yeah, that does exactly what I want. Thanks. 

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

tristaanogre
Esteemed Contributor

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
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: