QTP Script for Button control
Script to Click on OK Button
Dialog("Login").WinButton("OK").Click
Qtp Script to check whether Button is enabled or not(Disabled).
a=Dialog("Login").WinButton("OK").GetROProperty("enabled")
If a=true then
msgbox"ok button is enabled"
else
msgbox"ok button is not enabled"
End if
QTP Script for Combo box and other Controls
QTP Script for Button
QTP Script for Checkbox
QTP Script for checkbox
Syntax for checking or unchecking checkbox is
ObjectHierarchy.Set"on/off"
Script for above scenario will be
Window().Checkbox("one").Set "on"
Window().Checkbox("three").Set"on"
if u want to uncheck 3rd checkbox then
Window().Checkbox("three").Set"off"
QTP Script for Combo box and other Controls
QTP Script for Textbox
Script to enter value into Textbox
Dialog("Login").WinEdit("Agent Name:").Set "laxmiii"
Script to check whether particular textbox exist or not
If Dialog("Login").WinEdit("Agent Name:").Exist Then
Msgbox "The Textbox exists"
Else
Msgbox "The Textbox does not exist"
End if
If Textbox is present we get message as Textbox exist else we get message as Textbox doesnt exist.
QTP Script for Combo box and other Controls
QTP Script for Combo Box Control
QTP Script for Combobox
In combo box items index start from 0
1.Script for selecting an item from combobox using its value
Window("Flight Reservation").WinComboBox("Fly From:").Select “Frankfurt”
2. Script for selecting an item from combobox using its index
Window("Flight Reservation").WinComboBox("Fly From:").Select 1
1 indicates second item in combobox(0 for 1st item).
3.Script to get total items count of combobox
count = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
output will be 10.
4.Script to get value of selected item
selecteditem=Window("Flight Reservation").WinComboBox("Fly From:").GetSelection
Msgbox selecteditem
Output will be Frankfurt
5.Script to get all items(one by one) from combobox
count = Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
msgbox count
For i = 0 to count-1
item =Window("Flight Reservation").WinComboBox("Fly From:").GetItem(i)
Msgbox item
Next
Output -- single item will be displayed in messagebox
Total 10 message boxes will be displayed one after other.
6.Script to get names(content) of all items(at a time) from combobox
Content = Window("Flight Reservation").WinComboBox("Fly From:").GetContent
Msgbox Content
Output will be
Denver
Frankfurt
London
Los Angeles
Paris
Portland
San Francisco
Seattle
Sydney
Zurich
All items in one messagebox.
Data Driven Testing
SQL Queries Collection
QTP Script for Connecting to Database
QTP Script for Textbox Control
QTP Script for Checkbox Control
QTP Script for Button Control
QTP Script for RadioButton Control