Micro Focus QTP (UFT) Forums

Full Version: How to close all browsers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
thanks a lot. it works.
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,