Ask a Question

Property Wait to avoid Window destroyed error on Activate

SOLVED
colsson
Occasional Contributor

Property Wait to avoid Window destroyed error on Activate

Which property and property value should waited for before calling Activate on an object to avoid the error: "The window was destroyed during method execution".

 

 

Kind Regards

colsson

18 REPLIES 18
tristaanogre
Esteemed Contributor

What kind of object is it?  Because the last article you posted gave a suggestion for menu items... if that's what you're dealing with, could you verify?

As for what property to wait for... I'd actually wait for the object itself before you act on it... something like "WaitAliasChild" or "WaitChild".  Reference those help topics and see if they give you any insight.


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
colsson
Occasional Contributor

Thank you Mr. Martin!

 

 

No it is not a menu item. I posted that article link because that was the only article I could find on that subject.

 

  • Does both WaitAliasChild and WaitChild require the parent object or could they be used using just the object?
  • What would you do if you could not access the parent object?

 

 

Kind Regards

colsson

tristaanogre
Esteemed Contributor

If you cannot access the parent object, you have bigger problems...  that means that you have object identification problems further up the hierarchy.

 

It might help to know a bit more what automation code you are executing that is getting that error... we could probably find a way to get you what you need.


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
colsson
Occasional Contributor

I should have been more detailed in my previous answer!

I can access the parent object, but I do wonder why the parent is needed to wait for a particular state of the child?

 

The chain leading up to the Activate call which in turn causes a problem:

 

Set process1 = Sys.FindChild(...)

If process1.Exists Then

  Set child1 = process1.FindChild(...)

  If child1.Exists Then

   child1.Activate 'Works most of the time but may cause Window destroyed error

  End If

End If
  • process1 is: "msiexec"
  • child1 is a Form in the "msiexec"

Can you help me with that piece of code?

tristaanogre
Esteemed Contributor

It's not that you're waiting for the property of the child... you're waiting for the child itself with those "wait" methods.

 

Looking at your code:

 

So, you're using FindChild to find a process....  I wouldn't do it that way....  I'd use "Sys.WaitProcess" instead...  Then I'd do a WaitChild to wait for the child object of your process to be present...  

 

As for the "Activate"... not sure you need that... what are you hoping to do with "Activate"?


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
colsson
Occasional Contributor

 

  • Good explanation of the "wait" methods! I would still like to be able to wait for some "CanCallActivate" property on the child object though.
  • Thank you for the suggestion of changing FindChild to WaitProcess / WaitChild! I will try that.
  • Activate is used to ensure that the window is on top.

 

Kind Regards

colsson

colsson
Occasional Contributor

  • What is the advantage of using WaitChild over FindChild?
  • FindChild offers the searching capability of named property values compared to WaitChild which offers wildcard search, what if the search has to be done through FindChild would you then use WaitChild on the found object?
Set result = Utils.CreateStubObject
Set obj1 = obj.FindChild(...)
If obj1.Exists Then
  Set result = obj1.Parent.WaitChild(obj1.Name, timeout)
End If

 

tristaanogre
Esteemed Contributor

OK, I'm not sure I'd do that code...  

 

So... why use "WaitChild" over "FindChild"?  Wait allows you to customize the wait time for TestComplete to wait for the object to be present.  Now, just came to memory, you CAN use FindChildEx.  This combines the search functionality of FindChild with the Wait feature of WaitChild.  

 

If you use FindChildEx, make sure that you set the "refresh" property to "true".  That might help with the problem that you're originally reporting.  Basically, what's happening is that you're finding the object but after the object is found, it's destroyed and recreated... changing the in-memory handle of the object hence why it says it is destroyed before you are able to act on it.

 

So... there is something that's happening between when you run your application and when you try to find that child object that is causing that object to be destroyed and recreated.  If I was in your shoes, what I'd do is start doing some investigation around that startup process of your application to see if there is some other property or process or something that will give you an indication that the application is ready for interaction before you go searching for the child object.  


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
colsson
Occasional Contributor

For some unknown reason FindChildEx does not work while FindChild does work. (TestComplete 9)

Using FindChildEx would have been an improvement but it is not crucial.

 

Your description of the cause of the problem makes sense.

The .Refresh function is called on the function between finding it and calling .Activate on it, that could be the cause of this error which only happens infrequently.

 

I could not find anything to wait for to give an indication that the application is ready, I was hoping to find some corresponding property in TestComplete.

cancel
Showing results for 
Search instead for 
Did you mean: