8/2/2019 How to Close All Other Browsers
1/4
How to close all other browsers,except gmail,yahoo?
Code:bIndex = 0 'Set Browser index to 0While Browser("CreationTime:="&bIndex).Exist(1) 'Loop untill the
last browserbTitle =Browser("CreationTime:="&bIndex).GetROProperty("title") 'Get thebrowser title
If InStr(bTitle,"Google") = 0 And InStr(bTitle,"Yahoo") = 0And InStr(bTitle,"Gmail") = 0 Then
Browser("CreationTime:="&bIndex).Close 'If the titledoesn't contain Google or Gmail or Yahoo, close it
If bIndex 0 ThenbIndex = bIndex - 1 'If browser index is more than 0
and a browser is closed, decrease the index value by 1End If
ElsebIndex = bIndex + 1 'If no browser is closed for certain
run, increase the index value by 1End 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.
While Browser("CreationTime:="&bIndex).Exist(1) 'Loop untill thelast browser
bTitle =Browser("CreationTime:="&bIndex).GetROProperty("title") 'Get thebrowser title
If InStr(bTitle,"Google") = 0 And InStr(bTitle,"Yahoo") = 0And InStr(bTitle,"Gmail") = 0 Then
Browser("CreationTime:="&bIndex).Close 'If the titledoesn't contain Google or Gmail or Yahoo, close it
If bIndex 0 ThenbIndex = bIndex - 1 'If browser index is more than 0
and a browser is closed, decrease the index value by 1End If
ElsebIndex = bIndex + 1 'If no browser is closed for certain
8/2/2019 How to Close All Other Browsers
2/4
run, increase the index value by 1End If
Wend
There is another built-in functionality provided by QTP. That might not be pertinent to yourcase but you may want to explore.
Go to Tools -->Options -->Web
SystemUtil.CloseProcessByWndTitle "*.*", True
if Browser("micClass:=Browser","index:=0").Exist(0) Then
Browser("micClass:=Browser","index:=0").Close
Above line of code will close all the open Browsers.
Gmail application is there. On that Inbox so many mails arethere including naukari mails. On that mails i can select theonly naukri mail checkboxes.
Browser("Micclass:=Browser").Page("Micclass:=Page").WebEdit("name:=Email").Set""Browser("Micclass:=Browser").Page("Micclass:=Page").WebEdit("name:=Passwd").Set""Browser("Micclass:=Browser").Page("Micclass:=Page").WebButton("name:=Signin").ClickBrowser("Micclass:=Browser").Syncrowcount =Browser("Micclass:=Browser").Page("Micclass:=Page").Frame("htmlid:=canvas_frame").WebTable("class:=F cf zt").RowCountFor currentrow = 1 to 10'rowcount
mailsubject =Browser("Micclass:=Browser").Page("Micclass:=Page").Frame("htmlid:=canvas_frame").WebTable("class:=F cfzt").GetCellData(currentrow,3)
If mailsubject = "Naukri.com" Then
Set oChkbox =
8/2/2019 How to Close All Other Browsers
3/4
Browser("Micclass:=Browser").Page("Micclass:=Page").Frame("htmlid:=canvas_frame").WebTable("class:=F cfzt").ChildItem(currentrow,1,"WebElement",0)oChkbox.Click
End If
Next
A lternate way to call reusable action by script
you can use LoadAndRunAction only when the step runs and then run that actionThis is useful, for example if you may use many conditional statements that calls external actionsand you donot want to load all of the actions, each time you open the test as they may not benecessary during run session.
Syntax:
LoadAndRunAction(TestPath,ActionName,[iteration],[Parameters])
If i have understood correctly, you want create a f older and inside that f older create an excel f ile,
write some data in the excel f ile and save it, all dynamically. If that is the case, the code below might
help you achieve that:
Dim folderPath, folderName, xlFileName
//Provide folder path, folder name and excel file name
folderPath = "C:\"folderName = "MyFolder"
xlFileName = "MyExcel.xls"//Create File System ObjectSet fso = CreateObject("Scripting.FileSystemObject")//Build the folder pathnewPath = fso.BuildPath(folderPath,folderName)
//Create the folder if it is not created alreadyIf fso.FolderExists(newPath) True Then
fso.CreateFolder(newPath)End If
//Create Excel objectSet xlApp = CreateObject("Excel.Application")Set xlSheet=createObject("Excel.sheet")
//Write into excel file and save it inside the newly created folderxlSheet.ActiveSheet.cells(1,1).value=1111xlSheet.SaveAs newPath&"\"&xlFileName
Set xlSheet = NothingSet xlApp = NothingSet fso = Nothing
8/2/2019 How to Close All Other Browsers
4/4