QTP: GetRowWithCellText method – find the row number on a webtable with secified cell text

QTP: GetRowWithCellText method – find the row number on a webtable with secified cell text

GetRowWithCellText is an inbuilt QTP method which returns the number of the first row found that contains a cell with the specified text.

Syntax

object.GetRowWithCellText (Text, [Column], [StartFromRow])

  •  Column  – Optional – A Variant value. The column number where the cell is located. The value can either be the column name or index. Index values begin with 1.
  • StartFromRowOptional. A Long value. The number of the row in which to start the search. The first row in the table is numbered 1. 
  • In case the ,methos doesnot find any cell with specified text, the method returns -1 value.

Example –

 

‘The following example uses the GetRowWithCellText method to
‘find the row in the “OutboundFlights” table that contains the
‘text “Price” and then find the cell in that row that contains
‘a link and click it.

row = Browser(“Mercury Tours”).Page(“Search Results”).WebTable(“OutboundFlights”).GetRowWithCellText(“Price”, 2, 2)

 

Set Link = Browser(“Mercury Tours”).Page(“Search Results”).WebTable(“OutboundFlights”).ChildItem(row, 2, “Link”, 0)

 

Link.Click

This Post Has 10 Comments

  1. Sagar

    Amita,

    Is there any inbuilt function to validate the existence of a partucular text in the web table, provided not knowing row num and col num of the text to be searched?

  2. Amita

    Hi Sagar,

    Though there is not inbuilt function to directly cover you requirement. You may try the following code in case you are not sure about the row and column.

    row =0
    NoOfRows = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").GetRowCount
    for i=0 to NoOfRows
    NoOfColumns = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").ColumnCount(i)
    for i=0 to NoOfColumns
    row = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").GetRowWithCellText("Price", i, j)
    Next
    Next

    if row !=0
    msgbox "Price text exist in the webtable"
    else

    msgbox "Price text does not exist in the webtable"
    End If

    Hope it helps…:)

  3. Anonymous

    thanks it working fine

  4. NAMATUL

    hi,
    i need to verify existence of 3 value in 3 columns IN A WEBTABLE and i have to fetch the row number dynamically because at run time i have to create a order and than against that Order i have to search 2 value in 2 columns.Any idead

  5. anbu

    will not it work when you use directly getrowwithcelltext("text"), without providing row, clm since it is unknown?

    why should we looping all the rows here?

  6. Amita

    Yes Anbu, it should work…

  7. Atul Mhetre

    This method is not working for me as I am expecting –

    Lets say I am searching for 234
    Cell (2,2) is having 12345
    Cell (3,3) is having 234

    So I am expecting row 3 but it returns row 2.

    Do u have slon for this?

    regards,
    Atul Mhetre
    [email protected]

  8. Amita

    Hi Atul,
    I guess, it returns the first match. In your case, i hope that converting the string to number might help

  9. RAUSHAN RAJ

    I have one query regarding this post like if you want to perform RIGHTCKICK on that particular cell Value then what i should do?

  10. Anonymous

    Cell(2,2) can be compared with search data, if match, place the row no in array or otherwise go to next found row.

Comments are closed.