Tuesday, March 30, 2010

Do You Want To View Your Web Table's Structure?

Do you want to view your web table's structure? If the answer is Yes, then try the below snippet.
Set objTable=Browser("name:=Google").Page("title:=Google").WebTable("name:=q").Object
strTRCount=objTable.getElementsByTagName("TD").Length-1
For i=0 to strTRCount
objTable.getElementsByTagName("TD")(i).style.borderstyle="solid"
objTable.getElementsByTagName("TD")(i).style.borderwidth="2px"
objTable.getElementsByTagName("TD")(i).style.bordercolor="#98bf21"
Next
Try the above code with Google page, you will get the output as below.

Now, you are able to view all the cells of the webtable.

Saturday, March 27, 2010

How To Check Elements In A Weblist Are In Alphabetical Order


arrCtry=Split(Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items"),";")

Set objArray=DotNetFactory.CreateInstance("System.Collections.ArrayList","")

For i=0 to Ubound(arrCtry)
If arrCtry(i)<>"--Choose One--" Then
objArray.Add(arrCtry(i))
End If
Next

objArray.Sort()
objArray.Insert 0,"--Choose One--"

For j=0 to Ubound(arrCtry)
strOuput=strOuput+objArray(j)
strOuput=strOuput+";"
Next

If strOuput=Browser("name:=QTP").Page("title:=QTP").WebList("name:=select1").GetROProperty("all items")+";" Then
Msgbox "The Weblist's values are sorted in alphabetical order"
Else
Msgbox "The Weblist's values are not sorted in alphabetical order"
End If
I hope the above snippet is useful.

Sunday, March 14, 2010

Use WMI Code Creator Tool for Quick WMI Scripting

Are you searching for WMI codes? Or do you want to know about WMI classes and properties?

Microsoft has created an application to reduce our WMI scripting time. That is WMI Code Creator. This is a free tool from Microsoft. You can download it from the below link,

http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en

This tool reduces our WMI scripting time.
If anyone uses this tool, please include your comments. It may encourage QTP developers to opt this tool for quick WMI scripting.

Friday, March 12, 2010

Working with ChildItem and ChildItemCount methods

Consider a webtable has one row and two columns and the second column contains a webedit.
If you run the below code, Exist method will be passed and the value will be set into webedit.

If obj.ChildItem(1,2,"WebEdit",0).Exist(0) Then
obj.ChildItem(1,2,"WebEdit",0).Set "QTP"
End If
Suppose, if you run the code for negative condition (I.e. You are going to look for webedit in the first column where it does not exist), you will get an error as same as below.
To avoid this problem, use ChildItemCount method instead of ChildItem for the above criteria.

If obj.ChildItemCount(1,1,"WebEdit")>0 Then
obj.ChildItem(1,1,"WebEdit",0).Set "QTP"
End If
Now, you do not get the error for negative case.