Get cell data from webtable
Posted by rajivkumarnandvani on February 16, 2011
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 City
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
lee said
Thank you! Your blog help me solve my question.
rajivkumarnandvani said
Thanks for reading the blog.. 🙂
Balaji said
Superb
prasad said
hi
plz tell me
scenario : how to click a link in a cell of webtable (the cell consists of 4 links how to click the 2nd link
Anonymous said
Hi
i know how to click the single link in cell. May be this will helpful for u
Set wTable= Browser(“CorporateEmployees”).Page(“CorporateEmployees”).WebTable(“EmployeesTable”).ChildItem(RowNumber, CityColumn, “Link”, 0)
wTable.Click
navi said
Hi,
It was good.. i got another issue..
” If I am supposed to click on a particular column of a webtable which will change dynamically.. what i need to do”
wil getroproperty and settoproperty works fine with webtable…
i need clear script for the same…
Thanks,
Navi
Prasanna said
How to get the value to webtable when WT value is available with multiple page?
Thanks in advance