QTP中WebTable对象的常用方法

上一篇 / 下一篇  2015-05-06 11:48:00 / 个人分类:QTP

文章来源于:http://www.cnblogs.com/Automation_software/

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 (vtRowvtColumn)

参数

描述

object

类型 WebTable 的测试对象。

vtRow

必填. Variant 值。 单元格所在行的行号。表中的第一行编号为 1。

vtColumn

必填. Variant 值。 单元格所在列的编号。表中的第一列编号为 1。

返回类型

String 值。  返回指定单元格中包含的数据。
如果指定单元格无效,该方法返回 micCellDoesNotExist 

 

ChildItem 方法:

描述

按类型和索引返回单元格中的测试对象。

语法

object.ChildItem (RowColumnMicClassIndex)

参数

描述

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 bjTable=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 bjLink = objTable.ChildItem(intRow,intColumn,"Image",32) 
If  not objLink.Exist(0) Then
 msgbox "系统中没有您要找的菜单,请检查!"
 else
 objLink.click
End If


TAG:

 

评分:0

我来说两句

Open Toolbar