QTP - 子物件



包含在框架或視窗中的物件(文字框、組合框、連結)稱為子物件。有時,我們會遇到這種情況,需要獲取網頁中所有連結的屬性,或獲取視窗中所有單選按鈕的值。

在這些情況下,如果我們想對子物件進行操作,我們需要使用物件描述,透過它,我們將能夠對特定視窗/頁面中的所有物件進行操作。描述性程式設計將在即將到來的章節中詳細介紹,但本章的意義在於瞭解子物件及其用法。

以下指令碼從網站 "www.easycalculation.com" 中獲取連結的名稱

Dim oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Link"

'Find all the Links
Set obj = Browser("Math Calculator").Page("Math Calculator").ChildObjects(oDesc)

Dim i
'obj.Count value has the number of links in the page

For i = 0 to obj.Count - 1				
   'get the name of all the links in the page
   x = obj(i).GetROProperty("innerhtml") 
   print x 
Next

結果如下所示列印在輸出視窗中 −

Print Console
qtp_object_repository.htm
廣告
© . All rights reserved.