Ask a Question

How To Close All IE Browsers Except ALM

Occasional Contributor

How To Close All IE Browsers Except ALM

How To Close All IE Browsers Except IE browser in which ALM or QC is  open .? 
Super Contributor

In testcomplete using the object browser, check what is different in each IE opened, maybe the Page url is different or something...

After that just write a script or a bat file that closes every IE except the one with the property you want.
Occasional Contributor

Its not that easy as you have explained .

Do you have a code that returns the URL of each open IE browser Session ?

Even if we take a count of Open IE browesers ? how will you know the URL of each ?

i dont see any Such property in test complete .
Valued Contributor

I was bored so wrote this function for you...

Didn't fully test it or anything so you may modify as needed...enjoy...

function main(){


 JScript example

 this will close all explorer pages that do not contain google or yahoo in their page name




function closeIEPages(myBrowser,exclusionArray){

if (!Sys.WaitBrowser(myBrowser).Exists){



var browserArray = VBArray(Sys.FindAll('Name','*' + myBrowser + '*',1,true)).toArray();

for (var browser = 0;browser < browserArray.length;browser++){

 var objectArray = VBArray(browserArray[browser].FindAll(['Name'],['*Page*'],1,true)).toArray();

 for (var object = 0;object < objectArray.length;object++){

  var excludeTab = false;

  for (var exclusion = 0;exclusion < exclusionArray.length;exclusion++){

   if (objectArray[object].Name.indexOf(exclusionArray[exclusion]) != -1){

    excludeTab = true;




  if (!excludeTab && objectArray[object].Exists){






''-Praise the sun and Give Kudos.''
Super Contributor

@Ryan Moran "I was bored so wrote this function for you...

" AHAHAHAH, epic!

See @
Sumit Kumar, simple as I told you 😉
Occasional Contributor

The Reson why i say its not simple is : 

1. it has to close tabs if present in the open IE sessions .

2. sometimes when you Already have any broser session is open and then you invoke the tool it recognises it as window object .

3. The code given above is in javascript and i only use vbscript in my project .

4. i have wriiten a nice code in vbscript long back , it works fine in QTP , but when i tried to run it in test complete it dosnt work .

5. I am aware that there is difference in syntax of passing the Description of the object in qtp and test complete and i have changed that too .

6.but still dosn`t work  as  Desstop.childobjects  in qtp gives you all childobject  filter by all IE sessions , but no such method avalioble in tc ...

'==================Original QTP Code==========================


'Function Close_AllBrowser()


'Set oBrowser = Description.Create

'oBrowser("micclass").Value = "Window"

'oBrowser("regexpwndtitle").Value = ".*Internet Explorer.*"


'Set oDialog = Description.Create

'oDialog("micclass").Value = "Dialog"

'oDialog("text").Value = "Internet Explorer"

'oDialog("is owned window").Value = "True"

'oDialog("is child window").Value = "False"



' Set oBrowserList = Desktop.ChildObjects(oBrowser)


' Select Case oBrowserList.count 


' Case 0

'     Case 1

'  If Instr(oBrowserList(0).GetROProperty("text"), "Application Lifecycle Management") = 0 Then

' oBrowserList(0).Close

' wait(1)

' If oBrowserList(0).Dialog(oDialog).Exist(0) then 

' oBrowserList(0).Dialog(oDialog).WinCheckBox("text:=&Always close all tabs", "nativeclass:=Button").Set "ON"

' oBrowserList(0).Dialog(oDialog).WinButton("regexpwndtitle:=Close all &tabs", "text:=Close all &tabs").Click

' End if

'    End if


' Case Else

' For index = 0 to oBrowserList.count-1

'      If Instr(oBrowserList(index).GetROProperty("text"), "Application Lifecycle Management") = 0 Then

' oBrowserList(index).Close

' wait(1)

' If oBrowserList(index).Dialog(oDialog).Exist(0) then 

' oBrowserList(index).Dialog(oDialog).WinCheckBox("text:=&Always close all tabs", "nativeclass:=Button").Set "ON"

' oBrowserList(index).Dialog(oDialog).WinButton("regexpwndtitle:=Close all &tabs", "text:=Close all &tabs").Click

' End if

'      End if

' Next


' End Select


' Set oBrowser =Nothing


' Set oDialog = Nothing 


'End Function


Occasional Contributor

Anyone has a working code for this in VBscript ?
SmartBear Alumni (Retired)

Hi Sumit,


Will the following code work for you?

Function Close_AllBrowser


  Dim pages

  pages = Sys.Browser("iexplore").FindAllChildren("ObjectType", "Page", 2)

  For i=0 to UBound(pages)

    If aqString.Find(pages(i).LocationName, "Application Lifecycle Management") = -1 Then


    End If



End Function


The code checks all pages opened in IE and closes all except the one where Application Lifecycle Management is specified in the title.


Tanya Yatskovskaya
SmartBear Community and Education Manager

Occasional Contributor

Hi Tanya ,

Thanks for your kind help .

yes it is working fine .


I tried using the above said code, but its throwing me error (apologies, new to QTP, still learning stage)


Object requied: 'Sys'


can someone please help me


Thanks in advance

Showing results for 
Search instead for 
Did you mean: