We've all done it, right? We've started an IE instance, recorded/coded against it, and then when we're done, we've wanted to close it.
The trouble is that QTP has now forgotten which window is the correct one. Either the browser has changed in some small way, or we have too many open that are similar, or whatever. This doesn't happen often, but when it does, it's a royal pain
How do we ensure we can close the *correct* browser?
Lately, I've started storing the handle for the browser window I open in an environment variable. That way, using descriptive programming later, I *know* I can close the browser I want and nothing else.
Example:
Environment("BrowserHandle") = Browser("Browser).GetROProperty("hwnd")
Then later, to close:
Browser("hwnd:=" & Environment("BrowserHandle")).Close
This also works for anything, really. Navigate, or, like me, custom functions registered to your browser. I've found that while I always need this, there are many times when this really comes in handy and makes the process to get at a specific browser very efficient.
posted @ Wednesday, March 15, 2006 1:16 PM