您的位置:首页 > 编程语言 > Qt开发

QTP -20 Working with web Tables 与webTable交互

2012-02-06 16:19 411 查看

20 Working with web Tables

The biggest problem is to gain dynamically generated table.

20.1 The most important methods to work with table:

*RowCount: Returns the number of rows in the grid.

*ColumnCount(1) : Returns the number of rows in selected row

*GetCellData(1,1) : Returns the text contained in the specified cell. GetCellData (Row, Column)

*ChildItem (Row, Column, MicClass,
Index): Returns a test object from the cell by type and index.

*ChildItemCount (Row, Column, MicClass): Returns the number of objects of a specific type in the specified cell.

20.2 Access to dynamically generated table, not by OR.

--Using Index:

Browser("Browser").Page("Page").WebTable("Index:=3")

--Using Name or HTML ID:

Browser("Browser").Page("Page").WebTable("name:=TableName")

Browser("Browser").Page("Page").WebTable("html id:=TableId").

--Using innerText/outerText:(When table row heading text will be constant)

#Table caption text goes here

Attribute

value

Description

Align

Left

Center

right

Aligns the table. Deprecated.

Attribute2

Value2

Description2

# Using innerText by regular expression:

Browser("Browser").Page("Page").WebTable("innerText= Attribute.*value.*Description.*").

#Note: This method is not successful. E.g. Tables nested in table

20.2 Tables nested in the table

思路:通过innerTextby regular expression的属性,用描述性编程得到所有的tablecollection. 再把单个的webtable用item属性的分离出来。

20.3 Using OR to get dynamically generated table

思路:Add“innerText” as recognizing properties, and enter regular expression value “Attribute.*value.*Description.*”, then modifiesthe “index” value.

Note: We should run off Smart Identification for thewebTable, as it may lead to incorrect web table selection at runtime.

20.4 Using an object inside the table

思路:OR存有table里面的Object。 写一个方法利用这个object的parentNode方法得到webtable/table。

20.5 Clicking inside a WebTable

Method 1:

Browser("Browser").Page("Page").WebTable("Name").object.rows(1).Cells(1).Click

Method 2: (click WebElement in a table cell)

sIndex = Browser("Browser").Page("Page").WebTable("Name").object.rows(1).Cells(1).sourceIndex

Browser("Browser").Page("Page").WebElement("source_Index:=" & sIndex).Click

Method 3:

'Use concept of object identification hierarchy, first get Row object then Cell object

Set oWebTable = print Browser("Browser").Page("Page").WebTable("Name")

Set oRow = oWebTable.WebElement("html tag:=TR", "index:=0")

Set oCell = oRow.WebElement("html tag:=TD", "index:=0")

oCell.Click

Method 4:

‘Get 1st cell’s first link:

iEdit = Browser("Browser").Page("Page").WebTable("Name").ChildItem(1,1,"Link", 0)

20.6 Exporting WebTable to a DataTable

关键代码如下,其他的如标题的处理在实际项目中需要考虑:

For i = 0 To rowCount

dtSheet.SetCurrentRow i+1

cols= webTableObj.ColumnCount(i)

For j = 1 To cols

dtSheet.GetParameter(j).Value = webTableObj.GetCellData(i, j )

Next

Next

20.7 Search the string/text in the table by looping throughentire table

思路:用循环把table的所有值取出来比较即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: