QTP: A smarter way to access your browser

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.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Wednesday, March 15, 2006 1:16 PM

Feedback

# re: QTP: A smarter way to access your browser

left by Suhas at 1/11/2008 12:57 AM Gravatar
Set IE1=CreateObject("InternetExplorer.Application")
IE1.visible=True
IE1.navigate("www.google.com")

# re: QTP: A smarter way to access your browser

left by Kenny at 2/20/2008 11:00 PM Gravatar
hi Theo,

I'm trying the code that you have written, but am not able to get it to work, QTP still insists on closing the wrong windows... :<

Environment("BrowserHandle") = Browser("Website name").GetROProperty("hwnd")

Browser("hwnd:=" & Environment("BrowserHandle")).Close

Is this the way I use it? Or am I supposed to replace BrowserHandle or hwnd with something else?

# re: QTP: A smarter way to access your browser

left by Venkatram at 3/20/2008 4:40 AM Gravatar
We r Using browser Firefox, on which QTP does not support extensively.we run the recorded testcases,for which Dropdownlist box,radiobutton we manually given i/p,but using IE it is no problem, it is automatically taken input. Y this problem? Otherwise we have to set any environment variable to support Firefox extensively?

# re: QTP: A smarter way to access your browser

left by vreddy at 4/10/2008 12:32 PM Gravatar
I want to learn QTP, what way I can start
Comments have been closed on this topic.