Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to close all other browsers,except gmail,yahoo?
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi all,

Suppose there are many browsers which are opened, i want to close all browsers except gmail, yahoo, google. How should i script this in QTP?
Thanks in advance.....

Kalyani
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi Kalyani,

I don't understand on what situation you may need to leave few browsers and close rest all. Anyway, to achieve this, you can use the code below:

Code:
bIndex = 0 'Set Browser index to 0
While Browser("CreationTime:="&bIndex).Exist(1) 'Loop untill the last browser
    bTitle = Browser("CreationTime:="&bIndex).GetROProperty("title") 'Get the browser title
    If InStr(bTitle,"Google") = 0 And InStr(bTitle,"Yahoo") = 0 And InStr(bTitle,"Gmail") = 0 Then
        Browser("CreationTime:="&bIndex).Close 'If the title doesn't contain Google or Gmail or Yahoo, close it
        If bIndex <> 0 Then
            bIndex = bIndex - 1 'If browser index is more than 0 and a browser is closed, decrease the index value by 1
        End If
    Else
        bIndex = bIndex + 1 'If no browser is closed for certain run, increase the index value by 1
    End If
Wend

There is another built-in functionality provided by QTP. That might not be pertinent to your case but you may want to explore.

Go to Tools-->Options-->Web

Here you can see an option "Ignore the following browsers" where you can add your required browser details which QTP will ignore during record/run.
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi prabhat,

Thanks a lot, your code worked without any changesSmile.........but i dint understand logic completely.....i mean how it works, though u gave comments. I din understand line no:2,4. Thanks for ur time.

Kalyani
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
  How to delete particular mails in Gmail using QTP rajkumarsm 1 4,182 10-06-2014, 07:03 PM
Last Post: rajkumarsm
  Close browser code not working akilamurugesh 1 4,641 08-26-2014, 03:21 PM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 4 Guest(s)