Forum Discussion

rishi_1's avatar
rishi_1
Occasional Contributor
12 years ago

How to resolve this error Window was destroyed during method execution'.??

Every time I click on yes button to close a dialog I get 'Window was destroyed during method execution'







The error message is:



The window with the handle 0x00000000 does not exist.

Most likely, this error occurred because the tested object (window or control) or its parent object was deleted or recreated during the method call or before it. For instance, the window could be destroyed or recreated after you stored the object reference to a variable and before you called the object method through this variable.

If the object is recreated, then to avoid the error, check the object's Exists property before calling the method, and if the object does not exist, obtain a reference to the new object.





Please suggest me a generic solution to resolve this error.

12 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Sunitha,



    Basically, the error message description you've provided tells the most probable reason of the error: either the target object or one of its parents was recreated during the time you've set a reference to the object and used it. Note, that the reason of the error may be recreation of either the object itself or one of its parent object(s).

    For example, considering your sample, if you have something like this (pseudo-code):



    Set list = page.list

    Do

      Set div = list.FindChild(someDiv)

      div.link.click ' this opens some secondary popup or navigates to some other page

      ... ' proceed with the secondary popup and close it. Popup closing causes page.list recreation

    While Not exitCondition



    Then you will get the mentioned error because the list will be recreated (by jscript code on the page or by any other means) and your attempt to search for another div will use invalid list reference. In this case you will need to move Set list = page.list inside the Do loop to set the reference to the new list (even if it visually looks like the old one).



    Try to consult with developers or investigate the problematic page to find out if any of the parent object(s) can be recreated between using them in the test code.
  • sunireddy2007's avatar
    sunireddy2007
    Occasional Contributor
    Hi Alex,



    Thanks for the reply. You are right that the DIV list is dynalically updated with a "Show More" button. But the only previous object I use is the Page (web) object which I initialize at the beginning of the script via "Set pae = Sys.Browser(iexplore).Page("http://somesite.com/xyz/*")"



    I can re-initialize the page object reference and try.