cancel
Showing results for 
Search instead for 
Did you mean: 

How to check WinformsObject Exists or not

SOLVED
Contributor

How to check WinformsObject Exists or not

Hi,

i am trying to check WinformsObject exists or not but the  below code is not working 

if(Sys.Process.WaitWinFormsObject("DisplayScheduleMessage").Exists)

{

   Sys.Process.WinFormsObject("DisplayScheduleMessage").Close();

}

else

{

   Log.Message("Window doesnt exists continue next step");

}

 

Please advise.

 

 

Thanks,

5 REPLIES
Community Hero

Re: How to check WinformsObject Exists or not

There are timing issues that can affect checking for Exists.  Please take a look here:

 

https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

Highlighted
Contributor

Re: How to check WinformsObject Exists or not

Thanks and even i tried giving wait , but its not working

 if(Sys.Process("*").WaitWinFormsObject("DisplayScheduleMessage", 1000).Exists)

 {

   Sys.Process("*").WinFormsObject("DisplayScheduleMessage").Close();

 

}

else

 {

   Log.Message("Programme assigned");

 

}

 

Community Hero

Re: How to check WinformsObject Exists or not

Keep in mind that Sys.Process('*') will return the first process it finds in the search... which may not be your application.  You need to specify what process in order to detect the Winform.

 

Also... you say, "It's not working"... can you be more specific?  What is happening? Any errors? What's in the log?  


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.


I’ll be talking about “Hidden Treasures – TestComplete Script Extensions” at #SBConnect in October! Who’s joining me? Click here for tickets
Extensions available
Contributor

Re: How to check WinformsObject Exists or not

Thanks!

i tried the below code and its working.

var w = Sys.Process().WaitWinFormsObject("DisplayScheduleMessage", 1000);

if(w.Exists && w.VisibleOnScreen)

{

}

else

{

}

Community Hero

Re: How to check WinformsObject Exists or not

Actually, I would change your line of code to

var w = Sys.Process('myApp').WaitWinFormsObject("DisplayScheduleMessage", 1000);

 

Where you replace 'myApp' with the actual process name of your application under test.  Sys.Process() will, again, not necessarily return your specific application.


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.


I’ll be talking about “Hidden Treasures – TestComplete Script Extensions” at #SBConnect in October! Who’s joining me? Click here for tickets
Extensions available
Watch a new Video
Top Kudoed Authors