Micro Focus QTP (UFT) Forums
How to close all browsers - 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: How to close all browsers (/Thread-How-to-close-all-browsers)



How to close all browsers - bangla123 - 11-09-2010

Hi,

i am testing in web application using qtp9.2. I am doing FOR loop. Once one iteration finishes, I want to close all the browsers before I go to next iteration.
What would be the code to close all the browsers if there are any?

Thanks.


RE: How to close all browsers - rajeshwar - 11-09-2010

Hi,

Please try this.

Code:
'until no more browsers exist
While Browser("creationtime:=0").Exist(0)
'Close the browser
Browser("creationtime:=0").Close
Wend

Thanks,
Rajeshwar


RE: How to close all browsers - bangla123 - 11-09-2010

thanks a lot. it works.


RE: How to close all browsers - UFTEnthusiast - 01-04-2011

The following function closes all IE Browser instnces qucikly...!!

' This function closes down all IE browser instances - quickly!
'Parameters: None
'Returns: True

Public Function CloseAllIEBrowsers()

' Windows Management Instrumentation (WMI) is the infrastructure for management data
' and operations on Windows-based operating systems. You can write WMI scripts or
' applications to automate administrative tasks on remote computers but WMI also supplies
' management data to other parts of the operating system and products, for example System
' Center Operations Manager, formerly Microsoft Operations Manager (MOM), or Windows
' Remote Management (WinRM).

' This technique shuts down the processes (as seen in the Task Manager) instead of
' closing the actual window using its handle. Close all IE Browsers using WMI:

' I used this technique as it seemed more reliable and consistent than other approaches.

Code:
strSQL = "Select * From Win32_Process Where Name = 'iexplore.exe'"

    Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set ProcColl = oWMIService.ExecQuery(strSQL)

    For Each oElem in ProcColl
        oElem.Terminate
    Next

    Set oWMIService = Nothing[size=small]

    CloseAllIEBrowsers = True
    
End Function

Thanks,