WebTable對象用於測試Web頁面的表格對象。
對錶格對象的測試主要是擷取其中的資料,例如表格的行數、列數、儲存格的內容等。WebTable對象常用的方法有:ColumnCount、RowCount、GetCellData、ChildItem等。以下為四個方法的文法。
ColumnCount 方法:
描述
返回表中的列數。
文法
object.ColumnCount (Row)
參數 |
描述 |
object |
類型 WebTable 的測試對象。 |
Row |
必填. Long 值。 行號。表中的第一行編號為 1。 |
傳回型別
Long 值。
RowCount 方法:
描述
返回表中的行數。
文法
object.RowCount
參數 |
描述 |
object |
類型 WebTable 的測試對象。 |
傳回型別
Long 值。
GetCellData 方法:
描述
返回包含於指定儲存格中的文本。
文法
object.GetCellData (vtRow, vtColumn)
參數 |
描述 |
object |
類型 WebTable 的測試對象。 |
vtRow |
必填. Variant 值。 儲存格所在行的行號。表中的第一行編號為 1。 |
vtColumn |
必填. Variant 值。 儲存格所在列的編號。表中的第一列編號為 1。 |
傳回型別
String 值。 返回指定儲存格中包含的資料。
如果指定儲存格無效,該方法返回 micCellDoesNotExist
ChildItem 方法:
描述
按類型和索引返回儲存格中的測試對象。
文法
object.ChildItem (Row, Column, MicClass, Index)
參數 |
描述 |
object |
類型 WebTable 的測試對象。 |
Row |
必填. Long 值。 儲存格所在行的行號。表中的第一行編號為 1。 |
Column |
必填. Long 值。 儲存格所在列的編號。表中的第一列編號為 1。 |
MicClass |
必填. String 值。 物件類型。 |
Index |
必填. Long 值。 儲存格中 MicClass 類型的對象的索引。當儲存格中有多個 MicClass 類型的對象時,此索引指示所需的元素。第一個對象的索引為 0。 |
傳回型別
Object 對象。
執行個體一:
Dim RowCount
RowCount = Browser("Browser").Page("Page").WebTable("WebTable").RowCount
msgbox RowCount
For I = 2 to RowCount
cons_no=Browser("Browser").Page("Page").Frame("Frame").WebTable("html tag:=table","index:=2").GetCellData(4,2)
reporter.ReportEvent micDone,"使用者編號","使用者編號為:"&cons_no
Next
執行個體二:
Set objTable=Browser("creationTime:=0").Page("index:=0").Frame("name:=TreeMenuFrame").WebTable("html tag:=TABLE","index:=1")
dim intRow
intRow = Browser("creationTime:=0").Page("index:=0").Frame("name:=TreeMenuFrame").WebTable("html tag:=TABLE","index:=1").GetROProperty("rows")
dim intColumn
intColumn=Browser("creationTime:=0").Page("index:=0").Frame("name:=TreeMenuFrame").WebTable("html tag:=TABLE","index:=1").GetROProperty("cols")
Set objLink = objTable.ChildItem(intRow,intColumn,"Image",32)
If not objLink.Exist(0) Then
msgbox "系統中沒有您要找的菜單,請檢查!"
else
objLink.click
End If