Micro Focus QTP (UFT) Forums
Maximize and Close a Browser - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Maximize and Close a Browser (/Thread-Maximize-and-Close-a-Browser)



Maximize and Close a Browser - mv8167 - 01-13-2012

I have been trying the code below to Maximize and then close a Browser. But it is not working on line 4 , line 6 works

Code:
Browser("Browser").Page("Page").WebTable("Fax Status").Highlight(0)
Browser("Browser").Page("Page").Sync
hWnd = Browser("Browser").GetROProperty("hwnd")
Window("hwnd:=" & hWnd).Maximize
Window("hwnd:=" & hWnd).Close

I also tried:
Code:
hWnd = Browser("Browser").GetROProperty("hwnd")
title= Browser("micClass:=Browser", "hwnd:=" & hWnd).GetROProperty("title")
Window("title:=" & title).Maximize

But more than one Browser is open (i have 2 browsers open, only 1 called Browser)

What is wrong with my logic? I see this code all over the web.

thx


RE: Maximize and Close a Browser - vinod123 - 01-17-2012

Browser("micclass:=Browser).Close


RE: Maximize and Close a Browser - Munna.Sarfraz - 01-17-2012

This is the best way of closing Browser

Code:
Browser("Browser").Close


For Maximize
Code:
hWnd=Browser("Browser").GetROProperty("hwnd")
hWnd = Browser("hwnd:=" & hWnd).Object.hWnd
Window("hwnd:=" & hWnd).Activate
Window("hwnd:=" & hWnd).Maximize

Note: Its best practice to maximize window,
First get the handle of browser, then Activate then Maximize.

Regards,
Munna Sarfraz






RE: Maximize and Close a Browser - mv8167 - 01-18-2012

thx Vinod123 and Munna

Is it ok to use:

Code:
Window("hwnd:=" & hWnd).Close

I am thinking that Browser("Browser").Close may close the wrong browser window?

thx guys


RE: Maximize and Close a Browser - Mike B - 03-26-2023

[quote pid='19664' dateline='1326799441']
Code:
I had a General Run error when trying to get
hWnd = Browser("hwnd:=" & hWnd).Object.hWnd

In another forum I came across this code: (automationrepository)
and it worked without getting to the .Object.hWnd
Hope it might help someone.
hwnd = Browser("CreationTime:=0"").GetROProperty("top_level_hwnd")
Window("hwnd:=" & hwnd).Maximize


Regards,
Mike




[/quote]