cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with 'The window was destroyed during method execution'

SOLVED
Regular Contributor

Need help with 'The window was destroyed during method execution'

I have tried various methods to target the checkbox in question (see below), tried both 'Click' and 'ClickChecked' methods (both are listed in Object Spy > Methods tab).

 

The browser is terminated at the beginning of the script make sure there are no instances of the browser running. Also, the Mouse movement delay under Project Properties is set to 0.

 

The code I am using -

let page = Sys.Browser(iexplore).Page("*/THC*"); 
let panelUsers = page.FindChildEx("idStr", "Users", 10, true, 10000);
let chkRegression = panelUsers.FindChildEx("ObjectIdentifier", "UsersGrid_checkbox_Regression", 15,  true, 10000);

chkRegression.Click();

Got an error: 'The window was destroyed during method execution.'

Also, tried the following and got an error - 'TypeError: Cannot read property 'Click' of null'

aqUtils.Delay(300);
let chkRegression = panelUsers.QuerySelector(".panelUsersCheck"); 
//or 
let chkRegression = panelUsers.QuerySelector(#jqg_UsersGrid_*)

Using following did not help either.

  if (chkRegression.Exists){
    chkRegression.Click();
  }
  else {
    Log.Warning('Unable to find chkRegression');
  }

 

Thanks.

 

Dave

5 REPLIES
Community Hero

Re: Need help with 'The window was destroyed during method execution'

What it sounds like is that, while the FindChildEx returns the object, something is still process on the page that destroys and, potentially, recreates the object.  This is a standard problem in the world of Ajax and other such client side code execution.  You might need to add different code to detect that the page has completely refreshed, including all client side execution, before you do your Find calls.  

What the error means, FYI, has to do with object handles.  So, the FindChildEx returns an object with a handle... that handle gets destroyed and a new one gets created.  So, to us, the user, it all looks seemless.  But behind the scenes, the tool no longer has a hook into the object.  So, you need to make the tool wait longer before doing the FindChildEx.  A hard coded delay is a start.... but 300 milliseconds is probably not long enough.  I'd actually try that method but bump the delay up to 30000 milliseconds JUST as a diagnostic to make sure that waiting longer will fix the problem.  If a longer delay fixes the problem, then you need to make your code "smarter".


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

Re: Need help with 'The window was destroyed during method execution'

Thanks, Robert

 

Thanks for your help. I will start with the delay of 3000 as suggested and post the result here.

 

I have to admit that, I don't really understand the "... FindChildEx returns an object with a handle... that handle gets destroyed and a new one gets created. ...". I am sure you can help me with that when the time comes. Smiley Happy

 

Once again Thank you! 

 

Regular Contributor

Re: Need help with 'The window was destroyed during method execution'

Hi Robert

 

Thanks for your suggestion (also figured out what you meant by "... FindChildEx returns an object with a handle... that handle gets destroyed ...").  Smiley Happy

 

So here is the solution I came up with (the 'do - while' bit of code was shared by you in one of my earlier post - thank you!):

let chkUserRegression;
  do{
    count++;
    chkUserRegression = panelCurrentUsers.FindChildEx("ObjectIdentifier", "UsersGrid_checkbox_Regression", 15, true, 100);
  }
  while((!chkUserRegression.Exists)|| (count < 150));
  
  chkUserRegression.Click();

Oh! By the way, it took 1 minute and 6 seconds for the checkbox to be available for clicking!!

Community Hero

Re: Need help with 'The window was destroyed during method execution'

Hi Dave,

 

Great to hear that the problem has been identified and solution was found.

 

Just a minor note:

On the one hand:

> it took 1 minute and 6 seconds

while on the other hand, your code waits 100ms for the control to appear and retries up to 150 times without any intermediate delay. This results in 100ms * 150 = 15000ms = 15s.

So, the wait had to timeout in 15sec but not after 66sec.

The reason for this is an error in the condition - it must be And, but not Or:

while((!chkUserRegression.Exists) && (count < 150));

 

One more thing:

While in general wait in loop is correct thing, it is useful just in two cases:

1) When some additional processing might be required during the wait (e.g. if some intermediate window must be closed while waiting for the primary object); and

2) To be able to pause code execution during (extremely) long waits (like in your case). Without the loop the code will be paused only after wait timeout expires.

 

If the above are not the cases, the code may be simplified just to, say:

chkUserRegression = panelCurrentUsers.FindChildEx("ObjectIdentifier", "UsersGrid_checkbox_Regression", 15, true, 600000);

The above code will wait up to 10 minutes, but will continue if the sought for object is found earlier. So there is no performance penalty because of big value of the Timeout parameter.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Regular Contributor

Re: Need help with 'The window was destroyed during method execution'

Hi Alex, Thank you for pointing out my mistake! I really appreciate.

 

Dave

Share Your Stories
Read Latest News
Top Kudoed Authors