Hi all ,
I found a helpful example in QTP help file that can be use most of time while working with web table. I hope It will help you.
Description
Returns the text contained in the specified cell.Syntax
object.GetCellData (Row, Column)Argument | Description |
object | A test object of type WebTable. |
Row | Required. A Variant value. The row number where the cell is located. The first row in the table is numbered 1. |
Column | Required. A Variant value. The column number where the cell is located. The first column in the table is numbered 1. |
Return Value
A String value. Returns the data contained in the specified cell.
If the specified cell is not valid, the method returns micCellDoesNotExist
Find All Employees That Live in the Same CityIf the specified cell is not valid, the method returns micCellDoesNotExist
Sub GetCellData_GetRowWithCellText_Example()
‘The following example retrieves the names of all employees that live in
‘the same city as John Smith so that he can arrange rides home with them.
‘First, the example finds the table row containing
‘”John Smith”. Then it checks the value of the CityColumnn cell to determine
‘the city in which John lives. It searches the table cells to find all other
‘employees that live in that city. Finally it uses the GetCellData method to
‘return those employees names and, using a function, generates a list
‘containing those names.
CityColumn = 4
NameColumn = 2
‘Get the row number for employee ‘John Smith’
RowNumber = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).GetRowWithCellText(“John Smith”)
Set AccommodationsCity = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).ChildItem(RowNumber, CityColumn, “WebEdit”, 0)
TableRows = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).RowCount
‘Search for all employees that live in the same city as ‘John Smith’ and add them to his ride home list
For i = 1 To TableRows
Set CurrentCity = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).ChildItem(i, CityColumn, “WebEdit”, 0)
If CurrentCity.GetROProperty(“value”) = AccommodationsCity.GetROProperty(“value”) Then
EmployeeName = Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).GetCellData(i, NameColumn)
AddToJohnSmithRideHomeList (EmployeeName)
End If
Next
End Sub
1 comment:
Very Nice Post..
Post a Comment