1. How to Open an
existing word file
set word = createobject("word.application")
word.visible=true
Word.Documents.Open("C:\Documents and
Settings\sachin\My Documents\abc.docx")
Steps:
Create object for word application
Make the object visible
Open a new word file with help of open
method by specifying path
2 - How to launch a QTP application, open a new test and
close QTP through a
script.
Steps:
Declaring the application
object variable
Create the object
for qtp application
Invoke the qtp by
using launch method
Open new test with
help of qtp application object
Make qtp application
visible
Relesing the qtp app
object
3 - How to get data from Excel into QTP without importing
the Excel.

Steps:
Assign the path of excelfile to
variable
Assign the 1 to row,column variables
Declare the function for excel by
passing the path,sheet,row,column
Create an object of excel
Open the path of excel file by
using workbooks object
Assign the sheet data to variable
Closing the excel object
Release the excel object
Close the function
Using msgbox for viewing the
variables
4 - How to launch QTP, open a test, run it and close QTP.
Dim qtapp
Dim
qttest
Set
qtapp= createobject (“quicktest.application”)
Qtapp.launch
Qtapp.visible=
true
Qtapp.open”d:\aom1”,
true
Set
qttest=qtapp.test
Qttest.run
Qttest.close
Qtapp.quit
Steps:
Declaring the two variables qtapp,
qttest
Create an object for using quicktest.application.
Invoke the qtp by using launch
method
Open the desired test by using open
method
Assign the qtptest to an variable
Execute the test by using run
method
Close the test by using close
method
Close the qtp by using quit method
5.How to Open a new
word file
set word = createobject("word.application")
word.visible=true
set doc = word.documents.add
Steps:
Create object using word
application
Make the object visible
Open a new word file with help of
add method
6 - How to import excel into datatable in QTP.

Steps:
Declare the application object
variable
Create the application object
Launch the qtp
Open the test
Import the excel sheet data to
first sheet of data table
Export the runtime datatable to
excel sheet
Specify the qtp object visible
Relese the application object
7 - How to run all tests in a specific folder in QuickTest
professional (QTP)?
Dim qtp_app
Dim file_sys
Dim Dir
Dim test_collection
Set qtp_app =
CreateObject("QuickTest.Application")
qtp_app.Launch
qtp_app.Visible = True
' The file_systemObject object is used to access the file
system on the server. This object can manipulate files, folders, and directory
paths.
Set file_sys =
CreateObject("Scripting.filesystemObject")
'GetFolder: Returns a Folder object for a specified path
Set Dir = file_sys.GetFolder( "C:\Program
Files\HP\QuickTest Professional\tests1" )
Set test_collection = Dir.SubFolders
'RunResultsOptions:A collection of properties that indicate
preferences for the run results.
Set qtResultsObj =
CreateObject("QuickTest.RunResultsOptions")
For each t_folder in test_collection
qtp_app. Open t_folder.Path, True, False
'Setting the location for the run results
qtResultsObj.ResultsLocation = t_folder.Path &
"\Res1" ' Set the results location
' Execute the test. Instruct QuickTest Professional to wait
for the test to finish executing.
qtp_app.Test.Run qtResultsObj, True
qtp_app.Test.Close
Next
qtp_app.Quit
Set test_collection = Nothing
Set Dir = Nothing
Set file_sys = Nothing
Set qtp_app = Nothing
Steps:
Declare the variables for qtpobj,fsoobj,dir,testcollection
Create an object using filesysytemobject
Use the getfolder to returs a folder
Assign the subfolders to testcollcetion variable
Create the object using reunresultsoptions
Setting the location for the run
results
Execute the test. Instruct
QuickTest Professional to wait for the test to finish executing
Close the qtp by using close method
Relese the application
object,runresults object
8 - How to count and get the path & name of all the
object repositories associated with an action ?

Steps
Declare the
application object variable
Create the application object
Launch the qtp
Open the test
Retrive the object repositaries of
collection of action1
Count the no of object repositary
files in the collection
Returns the path of object
repossitary file
Extract the obkect repositary file
name
Getting the whole path in variable
Returh the specified no of chars
Relese the repositorys object ,
application object, testobject.
9 - How to count total number of links on a web page?
Set Des_Obj = Description.Create
Des_Obj("micclass").Value
= "Link"
Set link_col =
Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
msgbox link_col.count
Steps:
Create object using description
object
Assign link to object using value
method
Retrive the collection of all objects
& assign to variable
Using msgbox function dispay the
data present in variable
10 - How to get link names and URLs for all the links on a
web page?
Set Des_Obj = Description.Create
Des_Obj("micclass").Value
= "Link"
Set link_col =
Browser("name:=Google").Page("title:=Google").ChildObjects(Des_Obj)
a= link_col.count
For i=0 to a-1
tag =
link_col(i).GetROProperty("name")
href =
link_col(i).GetROProperty("url")
msgbox tag &" " &
href
Next
Steps:
Create object using description
object
Assign link to object using value
method
Using child objects assign to
variable
Assigning the data to variable by
using child objects
Count the links by using the count
function
Use for loop for repeting no of
links
Use getroproperty for capturing the name & url
11 - How to run multiple tests in QuickTest professional
(QTP) ?
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
Dim QTP_Tests(3)
QTP_Tests(1) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr1"
QTP_Tests(2) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr2"
QTP_Tests(3) = "C:\Program Files\HP\QuickTest
Professional\Tests\tr3"
'Creating the RunResultsOptions object. It is a collection
of properties that indicate preferences for the run results. E.g.
ResultsLocation property as used below which tells the path in which the run
results will be stored.
Set res_obj =
CreateObject("QuickTest.RunResultsOptions")
For i = 1 to UBound (QTP_Tests)
App.Open QTP_Tests(i), True
Set QTP_Test = App.Test
res_obj.ResultsLocation = QTP_Tests(i) &
"\Res1" ' Set the results location
QTP_Test.Run res_obj, True
QTP_Test.Close
Next
App.Quit
Set res_obj = nothing
Set QTP_Test = nothing
Set App = nothing
Steps:
Declare the application object
variable
Create the application object
Launch the qtp
Declare the array
Put the multiple tests in array
Create the results run object
Open the tests
Assign the tests to variables
Execute the test by using run method
Close the qtp using close method
Relese the application object, teset object
12 How to compare
two XML files.
Below are the two xml files used. There is very small
difference between these two XML files. Just try to understand how Compare
method gives results. You can always change/modify the code according to your
requirements.
XML file-1 - env.xml

XML file-2 - env1.xml

Using different XML files:
Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV1.xml"
res =
docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if
Results of running the above code:


Using same XML files:
Set doc=XMLUtil.CreateXML
doc.LoadFile "C:\ENV.xml"
Set docx=XMLUtil.CreateXML
docx.LoadFile "C:\ENV.xml"
res =
docx.Compare(doc,resultDoc,micXMLValues+micXMLCDataSections)
msgbox resultDoc
if res = 1 then
msgbox "Documents match :)"
else
msgbox "do not match "
end if
Results of running the above code:


Steps:
Assign the xml file to variable
Load the first xml file
Assign the xml file to variable
Load the second xml file
Compare the xml files by using
compare method and assigning result to variable
If the result variable is having value 1 then document same otherwise
not match
13. How to open a
new word document and writing text to it and saving it
set word = createobject("word.application")
word.visible=true
set doc = word.documents.add
Set objectSelection = Word.Selection
objectSelection.TypeText "This is sample text"
doc.saveas("c:\test.docx")
Steps:
Create object using word
application
Make the object visible
Open a new word file with help of
add method
Assign the word selection to
variable
Write the text by using Typetext
Save doc using saveas method
14.How to Print a word file
Set word = CreateObject("Word.Application")
Set objectdocument =
word.Documents.Open("c:\test.docx")
objectdocument.PrintOut()
word.Quit
Steps:
Create object using word
application
Open the desired document by using
open method
Print the document by using
printout method
Close the word document
15 - How Can I Add Additional Worksheets to an Excel
Workbook?
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
Set colSheets = objWorkbook.Sheets
colSheets.Add ,objWorksheet,9
Steps:
Create an object for excel
application
Assign the visible property as true
Add a sheet by using workbooks.add
method & assigning to variable
Assign sheet to variable
Add to the excelsheet
16 - How Can I Insert a Column into a Spreadsheet?
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Cells(1,1) = "Dataset 1"
objWorksheet.Cells(1,2) = "Dataset 2"
objWorksheet.Cells(1,3) = "Dataset 4"
Set objRange = objExcel.Range("C1").EntireColumn
objRange.Insert(xlShiftToRight)
Steps:
Create an object for excel
application
Assign the visible property as true
Assign the worksheet using
workbooks object
Assign the data to cells using work sheet methods
Using insert method insert
data by specifying
Const xlShiftToRight = -4161
17 - How Can I Replace Text in an Excel Spreadsheet?
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook =
objExcel.Workbooks.Open("C:\Scripts\Test.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange = objWorksheet.UsedRange
objRange.Replace "C:\Test\Image.jpg",
"C:\Backup\Image.jpg"
Steps:
Create an object for excel
application
Assign the visible property as true
Assign the excel file to the
variable by using workbooks & open function
Focus on particular sheet by using
workbook object
With the help of replace method we
can replace the text
18 ) How to Open an Excel Spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\New_users.xls")
Steps:
Declare the variables
Create the object using excel
application
Assign the excel file to the
variable by using workbooks & open function
19)
Create an Excel file, enter some data
and save the file through VB scripting?
Dim objexcel
Set objExcel = createobject("Excel.application")
objexcel.Visible = True
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Testing"
objexcel.ActiveWorkbook.SaveAs("f:\exceltest.xls")
objexcel.Quit
Steps:
Declare a variable for excelobject
Create an object for excel application
Set visible property as true for excelobject
Create an excel file by using workbooks object &
add method
Assign the data by using cells method by specifying row
& column nos
By using Activeworkbook
save the file by giving path
Close the excel object by using quit method
36) Creating a text File, doc file, excel
file, pdf file Using file system object
Dim objFso
Set objFso=CreateObject("scripting.FileSystemObject")
objFso.CreateTextFile ("E:\SRSS.txt")
objFso.CreateTextFile ("E:\SRSS.doc")
objFso.CreateTextFile ("E:\SRSS.xls")
objFso.CreateTextFile ("E:\SRSS.pdf")
Set objFso=CreateObject("scripting.FileSystemObject")
objFso.CreateTextFile ("E:\SRSS.txt")
objFso.CreateTextFile ("E:\SRSS.doc")
objFso.CreateTextFile ("E:\SRSS.xls")
objFso.CreateTextFile ("E:\SRSS.pdf")
Steps:
Create an object
for file system object
Use create text
file method with help of file system object by specifying path with extension
.txt
Use create text
file method with help of file system object by specifying path with extension
.doc
Use create text
file method with help of file system object by specifying path with extension
.xls
Use create text
file method with help of file system object by specifying path with extension
.pdf
37) Getting
available space on a Disk Drive
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oDrive = oFSO.GetDrive("C:")
MsgBox "Available space: " & oDrive.AvailableSpace
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oDrive = oFSO.GetDrive("C:")
MsgBox "Available space: " & oDrive.AvailableSpace
Steps:
Create an object
for file system object
Use getdrive method by specifying drivename & store in a
variable
Use msgbox for displaying available space with help of
availablespace method
38) 'Test Requirement: Open 1 to 10 orders
in Flight Reservation , Capture Customer names and Export into a Text file
Option Explicit
Dim Order_Number, Customer_Name, objFso, myFile
Set objFso=CreateObject("Scripting.FileSystemObject")
Set myFile= objFso.CreateTextFile ("C:\Documents and Settings\srss\Desktop",2)
myFile.WriteLine "Cusomer Names"
myFile.WriteLine "--------------------"
If Not Window("Flight Reservation").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4c48590870466b8dc050bbd24e816890c747ccf8"
Dialog("Login").WinButton("OK").Click
End If
For Order_Number= 1 to 10 step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Option Explicit
Dim Order_Number, Customer_Name, objFso, myFile
Set objFso=CreateObject("Scripting.FileSystemObject")
Set myFile= objFso.CreateTextFile ("C:\Documents and Settings\srss\Desktop",2)
myFile.WriteLine "Cusomer Names"
myFile.WriteLine "--------------------"
If Not Window("Flight Reservation").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4c48590870466b8dc050bbd24e816890c747ccf8"
Dialog("Login").WinButton("OK").Click
End If
For Order_Number= 1 to 10 step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight
Reservation").Dialog("Open Order").WinCheckBox("Order
No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set Order_Number
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Customer_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
wait (2)
myFile.WriteLine Customer_Name
Next
myFile.Close
Set objFso=Nothing
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set Order_Number
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Customer_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
wait (2)
myFile.WriteLine Customer_Name
Next
myFile.Close
Set objFso=Nothing
Steps:
Create the variable for
orderno,custname,fsoobject,myfile
Create an object for
filesystemobject
Open the text file using
filesystemobject by specifying path & assign to a
variable
Display the text “ Customer
names ” by using writeline method
Start if condition &
check whether flight reservation window
existed or not. If not invoke the flight
application using utility statement
Activate the login window
Enter data into agentname
field & enter mercury into password fields
Click on ok button
Close if condition
Start for loop 1 to 10 for
order novariable
Activate flight reservation
window
Activate menu item file go to
open prder
Select the check box order no “on”
Input the order no by using
the order no variable
Click on ok button
Capture the data present in
name edit box with help of getroproperty by specifying text property
Display the “ Customer names ” by using writeline method
by specifying customername variable
Repeat the loop by specifying
the next
Close the file by using close
method
Relese the file system object
by specifying nothing
39) Comparing
two text files
Dim f1, f2
f1="e:\SRSS1.txt"
f2="e:\SRSS2.txt"
Public Function CompareFiles
(FilePath1, FilePath2)
Dim FS, File1, File2
Set FS =
CreateObject("Scripting.FileSystemObject")
If FS.GetFile(FilePath1).Size
<> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 =
FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 =
FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
Do While File1.AtEndOfStream
= False
Str1 = File1.Read
Str2 = File2.Read
CompareFiles = StrComp(Str1,
Str2, 0)
If CompareFiles <> 0
Then
CompareFiles = True
Exit Do
End If
Loop
File1.Close()
File2.Close()
End Function
Call Comparefiles(f1,f2)
If CompareFiles(f1, f2) =
False Then
MsgBox "Files are
identical."
Else
MsgBox "Files are
different."
End If
Steps:
Declare the variables for
filestoterage
Assign the path of file to varables
Declare the function by
specifying file variable
Declare the variables for
filesystemobject,file1,file2
Create an object for file
system object
Start if condition by using
getfile method & compare the size of files
If satisfied returns true
& assign to function
Exit function
Close if condition
Open the files & store it
in a variable
Assign the false to function
Start do while loop by
specifying condition end of stream
Read the files & store in variables
Compare the files by using
strcomp function
Start if condition by
spefying condition function not equal to zero
If condition satisfied assign
true to function
Close the if condition
Repeat the loop
Close the files with help
of close method
Close the function
Call the function by
specifying file variables
Start if condition for
function & assign false to function
Display msg “files r
identical” by using msgbox
Otherwise
Display msg “files r not
identical” by using msgbox
Close if condition
40) Calculate the time taken to
complete login task of flight application with
out
using transaction points.
Ans:ST=Timer
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "SRSS"
Dialog("Login").WinEdit("Password:").SetSecure "4baf50f18b0ae0d5f5425fe760653e96da50bde7"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Activate
ET=Timer
TT=ET-ST
Msgbox TT
Steps:
- Assign timer function to a variable “ST” for storing start time
- Invoke the login winow of flight application by using utility statement
- Activate the login window
- Enter data into Agentname field
- Enter “mercury” into password fields
- Click on ok button
- Activate flight Reservation window
- Assign timer function to a variable “ET” for storing End time
- TT = ET-ST
- Use msgbox for displaying the Total time “TT”
41) Write a program for finding out whether the
given number is, Even number or Odd number?
Ans:
Dim num
Num = input box
("Enter a number")
If num mod 2=0 Then
msgbox "This is a Even Number"
Else
msgbox
"This is a Odd Number"
End If
Steps:
- Declare the variable
- Use input box to enter a no & store in varable
- Start if condition by specifying mod function (mod 2 = 0)
- If condition satisfied
- Display msg “even number “ using msgbox
- Otherwise
- Display msg “odd number” using msgbox
42) Find number of tables on webpage?
Ans:
SystemUtil.Run
"iexplore.exe","example.com"
Set oDesc = Description.Create ()
oDesc("html tag").Value =
"TABLE"
Set oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
MyTableCount = oChild.Count
Msgbox "We have " &
MyTableCount &" tables"
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use count method with child object(oChild) & store in a variable MyTableCount
- Use msgbox for displaying tables
- Relese childobject & description object
43) Find number of
rows on the first table of webpage?
Ans:
SystemUtil.Run
"iexplore.exe","example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value =
"TABLE"
Set oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
Total_rows=oChild(0).RowCount
Msgbox "Table has"
&Total_rows &"Rows"
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use rowcount for returning no of rows in a table using child object & store in a variable
- Use msgbox for displaying the no of rows
- Relese childobject & description object
44 )find number of
columns on the first row of first table of webpage?
Ans:
SystemUtil.Run "iexplore.exe","example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value =
"TABLE"
Set oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
Total_cols=oChild(0).ColumnCount(1)
Msgbox "This Row has"
&Total_cols &"Columns"
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use column count method for child object & store in variable
- Use msgbox for displaying the columns
- Relese childobject & description object
45) Retrive the data
from 4th row of 1st column on first table ?
Ans:
SystemUtil.Run
"iexplore.exe","example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value =
"TABLE"
Set oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
Datas=oChild(0).GetCellData(4,1)
Msgbox Datas
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use getcelldata method by specifying row& column for childobjec & store in variable
- Use msgbox for displaying the data
- Relese childobject & description object
46) Click on the
link on 4th row of table ?
Ans:
SystemUtil.Run "iexplore.exe","example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value =
"TABLE"
Set
oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
oChild(0).ChildItem(4,1,"Link",0).Click
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use childitem method with child object by specifyg (row,column,micclass,index ).click
- Relese childobject & description object
47) Type the text on
the textbox on 1st row of table?
Ans:
SystemUtil.Run
"iexplore.exe","example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value =
"TABLE"
Set
oChild=Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
oChild(0).ChildItem(1,1,"WebEdit",0).Set
"Qtp Tester"
Set oChild = Nothing
Set oDesc = Nothing
Steps:
- Invoke the internet explore using utility statement by specifying url
- Create a new description object to use for programmatic description & store the results in oDesc variable
- Specify the property name as html tag to description object by specifying TABLE as value
- Capture the collection of child objects using childobjects method & store in a child object variable “oChild”
- Use childitem method for retriving testobject by type & index for child object & use set method for giving data as input to textbox
- Relese childobject&description object
48)Count the Total number of Tables,rows and columns on the
page and retrieve it's content?
Sol:
SystemUtil.Run "iexplore.exe","http://example.com"
Set oDesc = Description.Create()
oDesc("html tag").Value = "TABLE"
Set oChild =
Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(oDesc)
'Counting number of tables on the page
MyTableCount = oChild.Count
Msgbox "We have " & MyTableCount &"
tables"
'Counting number of rows on the total table
For i=0 to MyTableCount-1
For Total_rows=1 to oChild(i).RowCount
Total_cols=oChild(i).ColumnCount(Total_rows)
Retrieved_data=oChild(i).GetCellData(Total_rows,Total_cols)
Msgbox "Table" &i &"has"
&Total_rows &"Rows"
Msgbox "Table" &i &"has"
&Total_cols &"Columns"
Msgbox "Datas:" &Retrieved_data
Next
Next
Set oChild = Nothing
Set oDesc = Nothing
Steps:
1.
Invoke the internet explore using utility statement by
specifying url
2.
Create a new description object to use for programmatic
description & store the results in oDesc variable
3.
Specify the property name as html tag to description
object by specifying TABLE as value
4.
Capture the collection of child objects using
childobjects method & store in a child object variable “oChild”
5.
Use count method with child object(oChild) & store
in a variable MyTableCount
6.
Use msgbox for displaying tables
7.
Start for loop for no of tables
8.
Use rowcount method for childobject & assign to
variable Total_Rows
9.
Use rowcount for counting no of columns & store in
variable Total_cols
10. Use
getcelldata method with child object by specifying total rows & columns as
arguments
11. Use
msgbox to display no of
rows,columns,retrive data
12. Repeat
the loop
13. Relese
child object, description object.
49) script for
read a value , count the data and Verify weather the value is Alfabet
are not?
Dim str, valAsc, flag,i
Dim strlen, counter,valsingle
counter=0
str=Inputbox("enter a string value")
strlen= Len(str)
For i=1 to strlen step 1
valsingle=Mid(str,i,1)
valAsc=Asc(valsingle)
If valAsc>=65 and valAsc<=90 or valAsc>=97 and valAsc<=122Then
flag=1
counter=counter+1
Else
flag=0
End If
Next
msgbox "No.of characters " &counter
If counter=strlen and flag=1Then
msgbox str&" is an Alphabetic value"
Else
msgbox str&" is not an Alphabetic value"
End If
Dim strlen, counter,valsingle
counter=0
str=Inputbox("enter a string value")
strlen= Len(str)
For i=1 to strlen step 1
valsingle=Mid(str,i,1)
valAsc=Asc(valsingle)
If valAsc>=65 and valAsc<=90 or valAsc>=97 and valAsc<=122Then
flag=1
counter=counter+1
Else
flag=0
End If
Next
msgbox "No.of characters " &counter
If counter=strlen and flag=1Then
msgbox str&" is an Alphabetic value"
Else
msgbox str&" is not an Alphabetic value"
End If
Steps:
- Declare the variables str, valAsc, flag,I, strlen, counter,valsingle
- Assign 0 to counter variable
- Accept the data using inputbox & store in str variable
- Use len method for counting no of chars & store in strlen variable
- Start for loop upto no of chars
- Use mid function by specifying str,i,1 to valsingle variable
- Use Asc function by specifying valsingle & store in valAsc variable
- Check whether valAsc>=65 and valAsc<=90 or valAsc>=97 and valAsc<=122 by using if condition
- If satisfied assign 1 to flag
- Increment counter variable by specifying counter+1
- Otherwise assign 0 to flag & close if condition
- Repeat the for loop
- Display no of chars using msgbox
- Check whether counter=strlen and flag=1 using if condition
- If satisfied use msgbox to display “Alphabet dat”
- Otherwise display “not an Alphabetic value”
50) Script to highlight all the child objects in Login
dialog of flight reservation application
Set chd_obj =
Dialog("text:=Login").ChildObjects
For i = 0 to
chd_obj.count - 1
chd_obj(i).Highlight
Next
Steps:
- Retrive collection of all objects contained with in the text:=Login dialog box & store the result in variable chd_obj objects
- use count method for counting no of child objects
- Use for loop upto no of objects
- Use highlight method for child object
- Repeat the loop
51) Script to highlight all the child
objects(buttons) in Login dialog of flight reservation application
Set button_obj =
Description.Create
button_obj("nativeclass").Value
= "Button"
Set chd_obj =
Dialog("text:=Login").ChildObjects(button_obj)
For i = 0 to
chd_obj.count - 1
chd_obj(i).Highlight
Next
Steps:
- Create new descriptive object to use for programmatic descriptions & store results in variable button_obj
- Retrive collection of all objects contained with in the text: =Login dialog box that match description button_obj & store the result in child object
- Use for loop upto no of objects
- Use highlight method for child object
- Repeat the loop
52)Script to check and uncheck all the
check boxes in open order dialog box of flight reservation application
Set checkbox_obj
= Description.Create
checkbox_obj("Class
Name").value = "WinCheckBox"
Set chd_obj =
Window("text:=Flight Reservation").Dialog("text:=Open
Order").ChildObjects(checkbox_obj)
For i = 0 to
chd_obj.Count - 1
chd_obj(i).Set
"ON"
chd_obj(i).Set
"OFF"
Next
Steps:
- Create new descriptive object to use for programmatic descriptions & store results in variable checkbox_obj
- Retrive collection of all objects contained with in the text: =Open Order dialog box that match description button_obj & store the result in child object
- Use for loop upto no of objects
- Use set method to check the checkbox
- Repeat the loop
No comments:
Post a Comment