SlideShare une entreprise Scribd logo
1  sur  6
For more QTP Realtime Scripts, visit www.ramupalanki.com

                             MS Excel Scripts

'''Script to create a new excel file , write data

'''save the file with read and write protected
'''''pwd1 is for read protected pwd2 is for write protected

Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Add
xl.DisplayAlerts=False
Set ws=wb.Worksheets("sheet1")
ws.cells(1,1)=100
ws.cells(1,2)=200
wb.Saveas "e:data2.xls",,"pwd1","pwd2"
wb.Close
Set xl=nothing


'''Script to open excel file ,which is read and write protected write data
'''''pwd1 is for read protected pwd2 is for write protected

Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:data2.xls",0,False,5,"pwd1","pwd2")
xl.DisplayAlerts=False
Set ws=wb.Worksheets("sheet1")
ws.cells(1,2)="hello"
ws.cells(2,2)="new data"
wb.Save
wb.Close
Set xl=nothing

''Script to get the list of links in Google and do spell check
=================================================
dim d
set mw=CreateObject("Word.Application")
set d=Description.Create
d("micclass").value="Link"
set a=Browser("Google").page("Google").childobjects(d)
for i=0 to a.count-1
mw.WordBasic.filenew
s=a(i).getROProperty("innertext")
mw.WordBasic.insert s
if mw.ActiveDocument.Spellingerrors.count>0 then

www.ramupalanki.com
For more QTP Realtime Scripts, visit www.ramupalanki.com

Reporter.ReportEvent 1,"Spelling","spelling error :"&s
end if
mw.ActiveDocument.Close(False)
next
mw.quit
set mw=nothing
=========================================
''''Script to check ON the checkboxes in yahoo mail inbox
=========================================
Dim d
Set d=Description.Create
d("micclass").value="WebCheckBox"
Set c=Browser("Inbox (17) - Yahoo! Mail").Page("Inbox (17) - Yahoo!
Mail").ChildObjects(d)
For i=1 to 10
c(i).set "ON"
Next
========================================
'''script to select a mail having subject 'hi' or 'HI'
========================================
n=Browser("yahoo").Page("yahoo").WebTable("Inbox").RowCount
For i=2 to n
s=Browser("yahoo").Page("yahoo").WebTable("Inbox").GetCellData(i,7)
If lcase(trim(s))="hi" Then
Browser("yahoo").Page("yahoo").WebCheckBox("index:="&i-1).set "ON"
End If
Next
========================================
'''''Function to send a mail
========================================
Function SendMail(SendTo, Subject, Body, Attachment)
Set otl=CreateObject("Outlook.Application")
Set m=otl.CreateItem(0)
m.to=SendTo
m.Subject=Subject
m.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
m.Send
otl.Quit
Set m = Nothing
Set otl = Nothing
End Function
www.ramupalanki.com
For more QTP Realtime Scripts, visit www.ramupalanki.com

Call SendMail("a@thdf.com","hi","This is test mail for testing","")
'''''''''''''''create a new text file
=================================================
Dim fs,f
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.CreateTextFile("e:file1.txt")
f.WriteLine "hello"
f.WriteLine "this is sample data"
f.Close
Set fs=nothing
=================================================
'''''''''''''''read data from a text file
=================================================
Dim fs,f
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile("e:file1.txt",1)
While f.AtEndOfLine<>True
msgbox f.ReadLine
Wend
f.Close
Set fs=nothing
=================================================
''''''''''create a new excel file and write data
=================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Add
Set ws=wb.Worksheets("sheet1")
ws.cells(1,1)=10
ws.cells(2,1)=20
ws.cells(3,1)=50
wb.SaveAs "e:file1.xls"
wb.Close
Set xl=nothing
=================================================
'''''''open existing file and write data in second column in Sheet1
=================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file1.xls")
Set ws=wb.Worksheets("sheet1")
ws.cells(1,2)="mindq"
ws.cells(2,2)="hyd"
ws.cells(3,2)="ap"
www.ramupalanki.com
For more QTP Realtime Scripts, visit www.ramupalanki.com

wb.Save
wb.Close
Set xl=nothing
=================================================
'''''''''''read data from excel from rows and columns
=================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file1.xls")
Set ws=wb.Worksheets("sheet1")
r=ws.usedrange.rows.count
c=ws.usedrange.columns.count
For i=1 to r
v=""
For j=1 to c
v=v&" "& ws.cells(i,j)
Next
print v
print "-----------------------"
Next
wb.Close
Set xl=nothing
=================================================
''''''''''''''''get the bgcolor in a cell in excel
=================================================
Dim xl,wb,ws
Set xl=CreateObject("Excel.Application")
Set wb=xl.Workbooks.Open("e:file3.xls")
Set ws=wb.Worksheets("sheet1")
r=ws.usedrange.rows.count
c=ws.usedrange.columns.count
For i=1 to r
For j=1 to c
x=ws.cells(i,j).interior.colorindex
msgbox x
Next
Next
wb.Close
Set xl=nothing
=================================================
'''''''''''''''''''''create word and write data
=================================================
dim mw
set mw=CreateObject("Word.Application")
www.ramupalanki.com
For more QTP Realtime Scripts, visit www.ramupalanki.com

mw.Documents.Add
mw.selection.typetext "hello"
mw.ActiveDocument.SaveAs "e:file1.doc"
mw.quit
set mw=nothing
=================================================
''''''''''script will display all the doc files in all the drives in the system
=================================================
Dim mw
Set mw=CreateObject("Word.Application")
Set fs=createobject("Scripting.FileSystemObject")
Set d=fs.Drives
mw.FileSearch.FileName="*.doc"
For each dr in d
msgbox dr
mw.FileSearch.LookIn=dr
mw.FileSearch.SearchSubFolders=True
mw.FileSearch.Execute
For each i in mw.FileSearch.FoundFiles
print i
Set f=fs.GetFile(i)
print f.Name&" "&f.Size&" "&f.DateCreated
print "-------------------------------------------------------------------"
Next
Next
mw.Quit
=================================================
'''''''''Open Internet Explorer and navigate to yahoomail
=================================================
Dim ie
Set ie=CreateObject("InternetExplorer.Application")
ie.Visible=True
ie.Navigate "www.yahoomail.com"
x=Browser("CreationTime:=0").GetROProperty("title")
msgbox x
=================================================
''''''Create word, Create table and write all the services names
=================================================
Set mw = CreateObject("Word.Application")
mw.Visible = True
Set dc = mw.Documents.Add()
Set objRange = dc.Range()
dc.Tables.Add
objRange,1,3
www.ramupalanki.com
For more QTP Realtime Scripts, visit www.ramupalanki.com

Set objTable = dc.Tables(1)
x=1
strComputer = "."
Set wms=GetObject("winmgmts:" & strComputer & "rootcimv2")
Set colItems = wms.ExecQuery("Select * from Win32_Service")
For Each s in colItems
If x > 1 Then
objTable.Rows.Add()
End If
objTable.Cell(x, 1).Range.Font.Bold = True
objTable.Cell(x, 1).Range.Text = s.Name
objTable.Cell(x, 2).Range.text = s.DisplayName
objTable.Cell(x, 3).Range.text = s.State
x=x+1
Next




www.ramupalanki.com

Contenu connexe

Plus de Ramu Palanki

Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answersRamu Palanki
 
Qtp interview questions3
Qtp interview questions3Qtp interview questions3
Qtp interview questions3Ramu Palanki
 
Qtp complete guide for all
Qtp complete guide for allQtp complete guide for all
Qtp complete guide for allRamu Palanki
 
Qtp compare two xml files
Qtp compare two xml filesQtp compare two xml files
Qtp compare two xml filesRamu Palanki
 
Qtp change excel cell color with condition
Qtp change excel cell color with conditionQtp change excel cell color with condition
Qtp change excel cell color with conditionRamu Palanki
 
Qtp certification questions
Qtp certification questionsQtp certification questions
Qtp certification questionsRamu Palanki
 
Qtp certification questions and tutorial
Qtp certification questions and tutorialQtp certification questions and tutorial
Qtp certification questions and tutorialRamu Palanki
 
Qtp certification questions2
Qtp certification questions2Qtp certification questions2
Qtp certification questions2Ramu Palanki
 
Qtp automation estimation techniques
Qtp automation estimation techniquesQtp automation estimation techniques
Qtp automation estimation techniquesRamu Palanki
 
Qtp 11 new enhacements in
Qtp 11 new enhacements inQtp 11 new enhacements in
Qtp 11 new enhacements inRamu Palanki
 
Qtp passing parameters between actions
Qtp passing parameters between actionsQtp passing parameters between actions
Qtp passing parameters between actionsRamu Palanki
 
Qtp wsh scripts examples
Qtp wsh scripts examplesQtp wsh scripts examples
Qtp wsh scripts examplesRamu Palanki
 
Quick test professional certifcation questions and tutorial2
Quick test professional certifcation questions and tutorial2Quick test professional certifcation questions and tutorial2
Quick test professional certifcation questions and tutorial2Ramu Palanki
 
Quality center certification questions
Quality center certification questionsQuality center certification questions
Quality center certification questionsRamu Palanki
 
Qtp+real time+test+script
Qtp+real time+test+scriptQtp+real time+test+script
Qtp+real time+test+scriptRamu Palanki
 
What are the features in qtp
What are the features in qtpWhat are the features in qtp
What are the features in qtpRamu Palanki
 
Testing interview questions
Testing interview questionsTesting interview questions
Testing interview questionsRamu Palanki
 

Plus de Ramu Palanki (20)

Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answers
 
Qtp interview questions3
Qtp interview questions3Qtp interview questions3
Qtp interview questions3
 
Qtp complete guide for all
Qtp complete guide for allQtp complete guide for all
Qtp complete guide for all
 
Qtp compare two xml files
Qtp compare two xml filesQtp compare two xml files
Qtp compare two xml files
 
Qtp change excel cell color with condition
Qtp change excel cell color with conditionQtp change excel cell color with condition
Qtp change excel cell color with condition
 
Qtp certification questions
Qtp certification questionsQtp certification questions
Qtp certification questions
 
Qtp certification questions and tutorial
Qtp certification questions and tutorialQtp certification questions and tutorial
Qtp certification questions and tutorial
 
Qtp certification questions2
Qtp certification questions2Qtp certification questions2
Qtp certification questions2
 
Qtp best tutorial
Qtp best tutorialQtp best tutorial
Qtp best tutorial
 
Qtp basic stuff
Qtp basic stuffQtp basic stuff
Qtp basic stuff
 
Qtp automation estimation techniques
Qtp automation estimation techniquesQtp automation estimation techniques
Qtp automation estimation techniques
 
Qtp 11 new enhacements in
Qtp 11 new enhacements inQtp 11 new enhacements in
Qtp 11 new enhacements in
 
Qtp sample resume
Qtp sample resumeQtp sample resume
Qtp sample resume
 
Qtp passing parameters between actions
Qtp passing parameters between actionsQtp passing parameters between actions
Qtp passing parameters between actions
 
Qtp wsh scripts examples
Qtp wsh scripts examplesQtp wsh scripts examples
Qtp wsh scripts examples
 
Quick test professional certifcation questions and tutorial2
Quick test professional certifcation questions and tutorial2Quick test professional certifcation questions and tutorial2
Quick test professional certifcation questions and tutorial2
 
Quality center certification questions
Quality center certification questionsQuality center certification questions
Quality center certification questions
 
Qtp+real time+test+script
Qtp+real time+test+scriptQtp+real time+test+script
Qtp+real time+test+script
 
What are the features in qtp
What are the features in qtpWhat are the features in qtp
What are the features in qtp
 
Testing interview questions
Testing interview questionsTesting interview questions
Testing interview questions
 

Dernier

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Qtp realtime excel scripts

  • 1. For more QTP Realtime Scripts, visit www.ramupalanki.com MS Excel Scripts '''Script to create a new excel file , write data '''save the file with read and write protected '''''pwd1 is for read protected pwd2 is for write protected Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Add xl.DisplayAlerts=False Set ws=wb.Worksheets("sheet1") ws.cells(1,1)=100 ws.cells(1,2)=200 wb.Saveas "e:data2.xls",,"pwd1","pwd2" wb.Close Set xl=nothing '''Script to open excel file ,which is read and write protected write data '''''pwd1 is for read protected pwd2 is for write protected Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:data2.xls",0,False,5,"pwd1","pwd2") xl.DisplayAlerts=False Set ws=wb.Worksheets("sheet1") ws.cells(1,2)="hello" ws.cells(2,2)="new data" wb.Save wb.Close Set xl=nothing ''Script to get the list of links in Google and do spell check ================================================= dim d set mw=CreateObject("Word.Application") set d=Description.Create d("micclass").value="Link" set a=Browser("Google").page("Google").childobjects(d) for i=0 to a.count-1 mw.WordBasic.filenew s=a(i).getROProperty("innertext") mw.WordBasic.insert s if mw.ActiveDocument.Spellingerrors.count>0 then www.ramupalanki.com
  • 2. For more QTP Realtime Scripts, visit www.ramupalanki.com Reporter.ReportEvent 1,"Spelling","spelling error :"&s end if mw.ActiveDocument.Close(False) next mw.quit set mw=nothing ========================================= ''''Script to check ON the checkboxes in yahoo mail inbox ========================================= Dim d Set d=Description.Create d("micclass").value="WebCheckBox" Set c=Browser("Inbox (17) - Yahoo! Mail").Page("Inbox (17) - Yahoo! Mail").ChildObjects(d) For i=1 to 10 c(i).set "ON" Next ======================================== '''script to select a mail having subject 'hi' or 'HI' ======================================== n=Browser("yahoo").Page("yahoo").WebTable("Inbox").RowCount For i=2 to n s=Browser("yahoo").Page("yahoo").WebTable("Inbox").GetCellData(i,7) If lcase(trim(s))="hi" Then Browser("yahoo").Page("yahoo").WebCheckBox("index:="&i-1).set "ON" End If Next ======================================== '''''Function to send a mail ======================================== Function SendMail(SendTo, Subject, Body, Attachment) Set otl=CreateObject("Outlook.Application") Set m=otl.CreateItem(0) m.to=SendTo m.Subject=Subject m.Body=Body If (Attachment <> "") Then Mail.Attachments.Add(Attachment) End If m.Send otl.Quit Set m = Nothing Set otl = Nothing End Function www.ramupalanki.com
  • 3. For more QTP Realtime Scripts, visit www.ramupalanki.com Call SendMail("a@thdf.com","hi","This is test mail for testing","") '''''''''''''''create a new text file ================================================= Dim fs,f Set fs=CreateObject("Scripting.FileSystemObject") Set f=fs.CreateTextFile("e:file1.txt") f.WriteLine "hello" f.WriteLine "this is sample data" f.Close Set fs=nothing ================================================= '''''''''''''''read data from a text file ================================================= Dim fs,f Set fs=CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile("e:file1.txt",1) While f.AtEndOfLine<>True msgbox f.ReadLine Wend f.Close Set fs=nothing ================================================= ''''''''''create a new excel file and write data ================================================= Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Add Set ws=wb.Worksheets("sheet1") ws.cells(1,1)=10 ws.cells(2,1)=20 ws.cells(3,1)=50 wb.SaveAs "e:file1.xls" wb.Close Set xl=nothing ================================================= '''''''open existing file and write data in second column in Sheet1 ================================================= Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:file1.xls") Set ws=wb.Worksheets("sheet1") ws.cells(1,2)="mindq" ws.cells(2,2)="hyd" ws.cells(3,2)="ap" www.ramupalanki.com
  • 4. For more QTP Realtime Scripts, visit www.ramupalanki.com wb.Save wb.Close Set xl=nothing ================================================= '''''''''''read data from excel from rows and columns ================================================= Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:file1.xls") Set ws=wb.Worksheets("sheet1") r=ws.usedrange.rows.count c=ws.usedrange.columns.count For i=1 to r v="" For j=1 to c v=v&" "& ws.cells(i,j) Next print v print "-----------------------" Next wb.Close Set xl=nothing ================================================= ''''''''''''''''get the bgcolor in a cell in excel ================================================= Dim xl,wb,ws Set xl=CreateObject("Excel.Application") Set wb=xl.Workbooks.Open("e:file3.xls") Set ws=wb.Worksheets("sheet1") r=ws.usedrange.rows.count c=ws.usedrange.columns.count For i=1 to r For j=1 to c x=ws.cells(i,j).interior.colorindex msgbox x Next Next wb.Close Set xl=nothing ================================================= '''''''''''''''''''''create word and write data ================================================= dim mw set mw=CreateObject("Word.Application") www.ramupalanki.com
  • 5. For more QTP Realtime Scripts, visit www.ramupalanki.com mw.Documents.Add mw.selection.typetext "hello" mw.ActiveDocument.SaveAs "e:file1.doc" mw.quit set mw=nothing ================================================= ''''''''''script will display all the doc files in all the drives in the system ================================================= Dim mw Set mw=CreateObject("Word.Application") Set fs=createobject("Scripting.FileSystemObject") Set d=fs.Drives mw.FileSearch.FileName="*.doc" For each dr in d msgbox dr mw.FileSearch.LookIn=dr mw.FileSearch.SearchSubFolders=True mw.FileSearch.Execute For each i in mw.FileSearch.FoundFiles print i Set f=fs.GetFile(i) print f.Name&" "&f.Size&" "&f.DateCreated print "-------------------------------------------------------------------" Next Next mw.Quit ================================================= '''''''''Open Internet Explorer and navigate to yahoomail ================================================= Dim ie Set ie=CreateObject("InternetExplorer.Application") ie.Visible=True ie.Navigate "www.yahoomail.com" x=Browser("CreationTime:=0").GetROProperty("title") msgbox x ================================================= ''''''Create word, Create table and write all the services names ================================================= Set mw = CreateObject("Word.Application") mw.Visible = True Set dc = mw.Documents.Add() Set objRange = dc.Range() dc.Tables.Add objRange,1,3 www.ramupalanki.com
  • 6. For more QTP Realtime Scripts, visit www.ramupalanki.com Set objTable = dc.Tables(1) x=1 strComputer = "." Set wms=GetObject("winmgmts:" & strComputer & "rootcimv2") Set colItems = wms.ExecQuery("Select * from Win32_Service") For Each s in colItems If x > 1 Then objTable.Rows.Add() End If objTable.Cell(x, 1).Range.Font.Bold = True objTable.Cell(x, 1).Range.Text = s.Name objTable.Cell(x, 2).Range.text = s.DisplayName objTable.Cell(x, 3).Range.text = s.State x=x+1 Next www.ramupalanki.com