Forum Discussion

royd's avatar
royd
Regular Contributor
6 years ago

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

  • 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".

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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".

    • royd's avatar
      royd
      Regular Contributor

      Hi Robert

       

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

       

      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!!

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        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.

         

    • royd's avatar
      royd
      Regular Contributor

      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. :)

       

      Once again Thank you!