Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetRowWithCellText does not work if the header has a colspan
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi all!

Actually I think I just post this to get rid of/share some more negative feelings about certain functions.

The method GetRowWithCellText (WebTable object) does not work if the header of the table does not match the "actual" columns of the table. By that I mean that the <th.. has a colspan of two, and each of the following lines contains 2 <td>.

When using GetRowWithCellText on such a table, it will only be able to find things in the first line (effectively the TH).

Again I will have to write my own methods, but if somebody else would like to add a solution or rant a bit along side me - please do so!

Cheers!
CC
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
Do you want to capture a value from a given row? or a cell?
Reply
#3
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi!

In advance: This is solved, I created my own function and that actually works..

But @Anshoo: No, this function is supposed to return a row number for a given text, so if there is a table and somehwhere in line 3 the word "test" occurs, normaly the this call GetRowWithCellText("text") should return 3. But that does not always work. Thanks anyway though! Smile

In case somebody wants to use my function, here it is. Its not very elegant, but I came to the conclusion that VBScript (or lets say the DotNet Object Model) does not want us to be elegant...

Code:
Function getTableRowWithText(table, textToFind, exact, uncountHeader)
    rows=table.rowCount()
    getTableRowWithText=-1
    if(table is nothing or textToFind="" or rows<1) then
        Exit function
    end if
    For i=1 to rows
        For j=1 to table.columnCount(i)
            val=table.getCellData(i, j)
            if(exact) then
                if(val=textToFind) then
                    getTableRowWithText=i
                    if(uncountHeader) then
                        getTableRowWithText=getTableRowWithText-1
                    end if
                    Exit function
                end if
            else
                if(instr(val, textToFind)>0) then
                    getTableRowWithText=i
                    if(uncountHeader) then
                        getTableRowWithText=getTableRowWithText-1
                    end if
                    Exit function
                end if
            end if
        Next
    Next
End Function
Reply
#4
Solved: 10 Years, 8 Months, 3 Weeks ago
hm, sorry, somehow the tabs got lost....
Reply
#5
Solved: 10 Years, 8 Months, 3 Weeks ago
nice of you ConstantChange for posting your solution to help others... if everyone shows the same spirit, this can indeed become a better place for QTP beginners and experts alike.

btw, you can use the "Preview Post" button (below) to preview your posts for any formatting errors etc.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#6
Solved: 10 Years, 8 Months, 3 Weeks ago
ConstantChange, you can also try this (a little simple and configurable):

Code:
Public Function getTargetRow(sText)

    Set oTable = Browser("micclass:=Browser").Page("micclass:=Page").WebTable("")
    rowTotal = oTable.GetROProperty("rows")
    colTotal = oTable.GetROProperty("cols")
    For rowStart = 1 to rowTotal
        For colStart = 1 to colTotal
            sData = ColInfoTable.GetCellData(rowStart,colStart)
            If sData = sText Then
                getTargetRow = rowStart
                Exit Function
            End If
        Next
    Next

End Function
Reply
#7
Solved: 10 Years, 8 Months, 3 Weeks ago
Thanks "ConstantChange" for posting this thread and for your proposed solution.

And thanks "Anshoo Arora" for your proposed solution, I tried it but it suffered also from the same problem that the "colTotal" always reads the first row columns. and the line "sData = ColInfoTable.GetCellData(rowStart,colStart)" needed small correction to be "sData = oTable.GetCellData(rowStart,colStart)". I've made small modifications to your function correcting the errors and adding 2 new parameters; the table as an input object and the table columns to make it more generic.

Code:
Public function getTargetRow(oTable, sText, colTotal)
    rowTotal = oTable.GetROProperty("rows")
    For rowStart = 1 to rowTotal
        For colStart = 1 to colTotal
            sData = oTable.GetCellData(rowStart,colStart)
            If sData = sText Then
                getTargetRow = rowStart
                Exit Function
            End If
        Next
    Next
End Function

To call this function:
Code:
Set myTableObject = Browser("myBrowser").Page(myPage").WebTable("myTable")
msgbox getTargetRow(myTableObject, "myText", 2)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Set the column header in the excelsheet before importing it to local datasheet nageshpv 2 3,188 08-04-2008, 04:05 PM
Last Post: nageshpv

Forum Jump:


Users browsing this thread: 1 Guest(s)