Automation – QTP Tips

Automation – QTP related tips. 
Sureshot things you should remember

. Used to refer to the Page

• Browser(“micClass:=Browser”) Used to refer to the Browser object • Page(“micClass:=Page”)

. Used to refer to a textfield

Object • WebEdit(“name:=txtAssertion”)  

• Eg


Is used to refer to the textfield “newDescription” on the current page within the current browser.

. To check the existence of the textfield


To set the value of the textfield to “Abhilash”
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“name:=newDescription”).Set “Abhilash”

• To check for buttons
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebElement(“innertext:=Save”, “html tag :=A”,”index:=1”).exist

• To click the Save button.
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebElement(“innertext:=Save”, “html tag :=A”,”index:=1”).Click

• To select an option from the dropdown
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebList(“name:=sel ectedEnumName”).select “Abhilash”

• To read the value of the textfield and store it in the variable
X X= Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“name:=newDescription”).GetROProperty(“value”) (Any property can be used to access the value and store the same).

• To select an option button.

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebCheckBox(“name =cmbCard”,”index:=2”).Set “ON”

• To derive the value from a datatable
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“name:=newDescription”).Set datatable(“ControlDescription”, globalsheet)
Where ControlDescription is the name of the column and globalsheet refers to the global sheet.

• Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“name:=newDescription”).Set datatable(“ControlDescription”, Sheet2)

Will read the data from Sheet2 under ControlDescription column

Code for synchronization
Environment.Value(“Class”) :=”creationtime:=1”
Set X = Browser(Environment.Value(“Class”)).Object
While (X.Busy = True OR X.ReadyStatus <> 4)
Set X = Browser(Environment.Value(“Class”)).ObjectWait 1

4 indicates Completed (hence checks for Not Completed to ensurecorrectness).

Setting value to a listbox

Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebList(“name:=selectedGroup”).Select “Abhilash”

Getting value from a listbox


Clicking a link

Clicking a Webbutton
Reading from a datatableBrowser(“micClass:=Browser”).Page(“micClass:=Page”).WebEdit(“name:=txtName”).Set Datatable(“FirstNames”,GlobalSheet)

Populating the WebList with the datatable contents
Browser(“micClass:=Browser”).Page(“micClass:=Page”).WebList(“name:=txtName”).Select Datatable(“FirstNames”,GlobalSheet)

Writing to datatable
Datatable(“FirstNames”,GlobalSheet) = “Abhilash”

To get the rowcount
intRow = DataTable.GetRowCount

To set the current row to 5

Importing data from an Excel sheet
Datatable.ImportSheet , ,
Where is the Name or Index of the sheet is the name or index of the datatable.
Eg Datatable.ImportSheet “C:AbhiAbc.XLS”, 4,”Global”OrDatatable.ImportSheet “C:AbhiAbc.XLS”, “MYSheet”,”Global”

– Environment Variables in QTP
– ActionIteration : The action iteration currently running.
– ControllerHostName : The name of the controller’s computer. This variable is relevant only when running as a GUI VUser from the LoadRunner controller.
– GroupName : The name of the group in the running scenario. This variable is relevant only when running as a GUI VUser from the LoadRunner controller.
– LocalHostName: The local host name.
– OS :The operating system.
– OSVersion :The operating system version.
– ProductDir :The folder path where the product is installed.
– ProductName: The product name.
– ProductVer :The product version.
– ResultDir :The path of the folder in which the current test results are located.
– ScenarioId: The identification number of the scenario.


One thought on “Automation – QTP Tips”

  1. Thanks for your Excellent initialization to start QTP from the basics.One kind suggestion is that,a training would be even more helpful if you can explain the upcomings information with simple examples and screenshots, so that it would help the concepts clearly.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s