Forum Discussion
providing code and log screenshot also. Please find the attachment
- tristaanogre10 years agoEsteemed 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.
- tristaanogre10 years agoEsteemed 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...
- kjadhavkunal10 years agoContributor
I copied the same code to the other script(i.e file). And the execution was as expected.
- Colin_McCrae10 years agoCommunity Hero
It worked this time.
But it may not continue to work.
As tristaanogre, you have short, hard coded, delays. These assume that object will always be present/destroyed within the 1 second you have defined. If you start getting intermittent failures again, I agree with him, this is the most likely reason.
Hard coded magic numbers = BAD.
You should always check for existence/visibility of objects before using them. Relying on hard coded waits and suchlike is never good.
I also agree with his comments on your Find searches. But, if you are confident that the text searched for will always be unique on the page, then you should be OK. But you are searching from a very high level within the DOM, and searching deep, so it has plenty opportunity to find false positives. As well as not being very efficient.