This article demonstrates a quick tip to activate, minimize or maximize browsers. Unlike a Standard Windows Window object, Browser does not support the Activate, Minimize, Maximize methods. Therefore, we can create our custom function and tie it with the Browser object using RegisterUserFunc.
The only trick is to retrieve the Browser Handle and substitute the handle in the description of a Window object, and use the Window’s Activate method instead.
Activate Browsers:
Function BrowserActivate(Object) Dim hWnd hWnd = Object.GetROProperty("hwnd") On Error Resume Next Window("hwnd:=" & hWnd).Activate If Err.Number <> 0 Then Window("hwnd:=" & Browser("hwnd:=" & hWnd).Object.hWnd).Activate Err.Clear End If On Error Goto 0 End Function RegisterUserFunc "Browser", "Activate", "BrowserActivate"
After registering the BrowserActivate function with the Browser object as Activate we can use it just like we would use it for a Window object:
Browser("title:=Relevant Codes.*").Activate
BrowserActivate can be extended to maximize and minimize a browser window as well. The only extra statement to be included in the function would be the maximize and minimize methods of the window object.
Minimize Browsers:
Function BrowserMinimize(Object) Dim hWnd hWnd = Object.GetROProperty("hwnd") On Error Resume Next Window("hwnd:=" & hWnd).Activate If Err.Number <> 0 Then hWnd = Browser("hwnd:=" & hWnd).Object.hWnd Window("hwnd:=" & hWnd).Activate Err.Clear End If Window("hwnd:=" & hWnd).Minimize On Error Goto 0 End Function RegisterUserFunc "Browser", "Minimize", "BrowserMinimize"
Maximize Browsers:
Function BrowserMaximize(Object) Dim hWnd hWnd = Object.GetROProperty("hwnd") On Error Resume Next Window("hwnd:=" & hWnd).Activate If Err.Number <> 0 Then hWnd = Browser("hwnd:=" & hWnd).Object.hWnd Window("hwnd:=" & hWnd).Activate Err.Clear End If Window("hwnd:=" & hWnd).Maximize On Error Goto 0 End Function RegisterUserFunc "Browser", "Maximize", "BrowserMaximize"
If you would like to use the above 3 methods through a single function or class, they can be coupled together through Execute statements or through If-Then or Switch-Case blocks. Happy reading!
If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.
{ 20 comments… read them below or add one }
Thanks for the useful info.
http://qualitypointtech.net/ebook/index.php
:)
Hey anshoo
r u really doing a grt job
keep it on ….I am a beginner in QTP so some of ur codes are bouncing over my head :)
plzz can u suggest me some good sites where I can get every tit bit idea abt QTP and after tht i will go thru ur codes I will get tht completely
I have included a few websites in the Links section of Relevant Codes. They are all excellent resources which will certainly be helpful to you :)
hWnd = Browser(“hwnd:=” & hWnd).Object.hWnd
Here, handle of the run-time object’s window ‘hWnd’ is used to identify Browser object.
But, I did not get the idea of getting the same value.
Could you please explain me about this?
This is a workaround for IE7+ versions because of tabbed browsing. If you have IE7 or greater, use your Object Spy to spy on the Browser object and you will find 2 different hWnd values – Test and Native. Thus, the Test time hWnd is used to retrieve the Native hWnd.
Thank you…:-)
Hi Good Effort , Thank you
Hey , If any one have idea please tell me “Why” QTP Does not support
tab browsing ?
Deep,
What version of QTP are you using?
Yes Anshoo
I am using QTP 9.0
Does the version matters for Tab
Is there any version which supports Tab in browser.
Yes Anshoo
I am using QTP 9.0
Does the version matters for Tab
Is there any version which supports Tab in browser.
Deep,
I think tabbed browsing was supported after version 9.5..
You are doing gr8 job , Thank you!!!!
how do u capture the browser object when it happens to be the parent object….i used the followin code and it errors out…
Set oBrowser = Description.Create()
oBrowser(“micclass”).value = “Browser”
oBrowser(“name”).Value = “Edit Study.*”
oBrowser(“title”).Value = “Edit Study.*”
hWnd = oBrowser.GetROProperty(“hwnd”)…..it errors out over here…
Hi Sunny,
You cannot directly use the description object like that. It should be this instead:
Set oBrowser = Description.Create() oBrowser("micclass").value = "Browser" oBrowser("name").Value = "Edit Study.*" oBrowser("title").Value = "Edit Study.*" hWnd = Browser(oBrowser).GetROProperty("hwnd")how u will open a page using browser navigation
what is hwnd in programming
Hi edwina,
A hWnd is the abbreviation of “Window Handle” which is an unique identifier. The browser or windows are assigning unique value to this property. So, we can use this property for the browser identification.
Thanks,
Sivaram S
hi
in the above conversations , i have seen a code
hWnd = Browser(“hwnd:=” & hWnd).Object.hWnd
could you highlite some information on { .object.hwnd} in the above line of code. i mean how exatcly this .object works
Thanks in advance
Vasudev
When you see
.Objectbeing used, it means, the code is working with the native properties instead of TO properties. In the object spy, there are radio buttons for Test Object properties as well as Native properties. The use of .Object points to the latter.