Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to close all browsers
#1
Solved: 11 Years, 4 Months ago
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.
Reply
#2
Solved: 11 Years, 4 Months ago
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
Reply
#3
Solved: 11 Years, 4 Months ago
thanks a lot. it works.
Reply
#4
Solved: 11 Years, 4 Months ago
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,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Maximize and Close a Browser mv8167 4 16,662 03-26-2023, 03:55 PM
Last Post: Mike B
  Close popup ad windows dustwynn 1 2,961 10-25-2016, 05:57 PM
Last Post: Ankur
  [UFT] Close opened folder robertosalemi 1 3,353 02-10-2016, 07:06 PM
Last Post: robertosalemi
  Close browser code not working akilamurugesh 1 4,640 08-26-2014, 03:21 PM
Last Post: vinod123
  Close on Exit Issue in QTP 11.0 EGBELL 1 3,209 02-02-2014, 03:39 PM
Last Post: EGBELL

Forum Jump:


Users browsing this thread: 1 Guest(s)