Sunday, November 28, 2010

Unknown QTP Webtable Methods

The below listed unknown QTP webtable methods were present in Astra LoadTest. But we are still able to use these methods in QTP. I would like to share this to you.

#1 CellText
This method works as same as GetCellData method.
Eg.: Msgbox Browser("name:=qtp").WebTable("index:=0").CellText(1,1)

#2 CellTextByContext
This method returns the text within a cell delimited by a character. We can retrieve the text before (or) after the delimiter using this method.
Eg.: Consider a cell having the text “Asiq;Ahamed”. Here “;’ is the delimiter

Code to retrieve the text before the delimiter
Msgbox Browser("name:=qtp").WebTable("index:=0").CellTextByContext(1,1,"",";")

Code to retrieve the text after the delimiter
Msgbox Browser("name:=qtp").WebTable("index:=0").CellTextByContext(1,1,";")

#3 TextCellExist

This method checks whether a text exists in a cell or not. It returns true, if the input text exists in the cell, else it returns false. Rather than using GetCellData method and then comparing the result with the input text, we can achieve it using this simple method.
Msgbox Browser("name:=qtp").WebTable("index:=0").TextCellExist(1,1,"asiq")
I hope this is useful to all.

Sunday, November 21, 2010

Beware of setting value in webedit using DOM

If you set value in a disabled webedit, QTP will throw the below error.


But do not enter value in webedit using DOM. The problem is: You can set value in web text box even it is disabled.
We have a work around for this.

Set obj=Browser("name:=Google").Page("title:=Google").WebEdit("index:=1").Object
If Not obj.disabled Then
obj.Value ="qtp"
End If
I always use DOM to retrieve text or count no. of objects. I hope this is helpful.