Forum Discussion

kjadhavkunal's avatar
kjadhavkunal
Contributor
9 years ago

The window was destroyed during method execution error

      I have been running this script for last 2 weeks. From this morning the same script is showing above error. I restarted the machine re-identified the object still its not working.

      I was debugging the same and object identification was successful also the window is available, still it is showing an error the window was destroyed. 

       Please find the below screenshot for more details.

6 Replies

  • providing code and log screenshot also. Please find the attachment

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Based upon the following thread https://community.smartbear.com/t5/TestComplete-Functional-Web/The-window-was-destroyed-during-method-execution/td-p/74999 here's my thinking.

       

      Your code is doing a hard coded 1 second delay before clicking on the item. This MIGHT not be enough time.  Generally, what the error that you are experiencing means is that between the time that the object was assigned to the Listitem var and when you went to click on it, it was destroyed and recreated or something like that.  This is one of the drawbacks with "FindChild", especially with highly dynamic web pages, because it may find an object at one point and assign a reference to it but the object may get re-created after that.

       

      What I would do is, before you call Listitem.Click(), I would check the Exists property of Listitem... something like

       

      var Listitem = page.FindChild(props, vals, 10);
      if (Listitem.Exists) {
          Listitem.Click();
      }
      else {
          Log.Warning('Unable to find Listitem');
      }

      Some thing alse you can do is see if you can first find the parent object of your Listitem and then do a WaitChild call on it to make sure that you get a good reference to your object.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Another note on this... FindChild will find the FIRST child that matches your search criteria... you're searching a tree depth of 10 which means that it is possible that there is an object at layer 3 or 5 or 7 or whatever that matches what you are looking for and that object, when you go to click on it, may be getting destroyed. So, one thing you can try is to verify that 10 is the EXACT depth to find your object so the depth of your search is optimized.  Then, before your FindChild call, call the following line of code:

         

        Options.Run.ObjectSearchStrategy = searchDepthFirst;

        By default, for new installations and new projects, TestComplete does the FindChild search on breadth-first... it searches each level before it goes one level deeper. So, FindChild will find something on a lower level rather than dive deep first.

        Beyond that... You might need to get more specific with your FindChild parameters... are there other properties that will more uniquely find the item you are looking for? Something that will guarentee you'll get the correct item and not some other similar item in the object tree?

         

        Just some things to try...