Micro Focus QTP (UFT) Forums
QTP 9.5 - Select an element in a table - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: QTP 9.5 - Select an element in a table (/Thread-QTP-9-5-Select-an-element-in-a-table)



QTP 9.5 - Select an element in a table - SAKDOSS - 07-29-2009

Hello,

I would like to select one precise element in a table (a JTable in fact but I think it's quite similar) and I don't know how to do it.

For example, if I have the table :
Code:
Column 1  | Column 2
-----------------------
z         |   Name1
k         |   Name2
b         |   Name3
d         |   Name4

How can I select the name in "Column 2" which correspond to the line which contains 'k' in "Column 1" ?

Of course this line is not always the second.

Thanks in advance !


RE: QTP 9.5 - Select an element in a table - supputuri - 07-30-2009

Hi SAKDOSS ,
Code:
If Browser(X).Page(X).WebTable("index:= Here mention UR table index").Exist Then
    ColNum = Browser(X).Page(X).WebTable("index:= Here mention UR table index").ColumnCount(1)
        DesiredColNum = 0
        For colint = 1 to ColNum
            If Browser("SAM").Page("SAM").WebTable("Database:").GetCellData(1,colint) = "Column2" Then
                DesiredColNum = colint
                Exit For
            End If
        Next
        If DesiredColNum <> 0 Then
            For rowint = 1 to Browser("SAM").Page("SAM").WebTable("Database:").RowCount
                    rowval = Browser("SAM").Page("SAM").WebTable("Database:").GetCellData(rowint,1)
                    If rowval = "k" Then
                        DesiredRow = rowint
                        Exit for
                    End If
            Next
        Else
            MsgBox "Column2 is not displayed in the specified table."
        End If
        
        MyValue = Browser("SAM").Page("SAM").WebTable("Database:").GetCellData(rowint,DesiredColNum)
        msgbox MyValue
        
Else
    msgbox "Specified WebTable with ''" & Here mention UR table index & "'' is not present."
    ExitRun
End If

Please let me know if you need any more info.


RE: QTP 9.5 - Select an element in a table - venkatbatchu - 07-30-2009

Please see the attached document and go through the query so that u would feel much comfortable
Scenario:

When I record the application it is taking same object multiple times like “+” is a grow button then in object repository it is taking multiple times as growbutton_1, growbutton_2, growbutton_3,…..
And the same way for the fields (area, assigned to, originator) which is taking as “Select field”, selectfield_1, selectfield_2,……

While running the application as in OR it is having multiple object and able to run successfully when I use the descriptive programming it is not running successfully

My observation:
While running the application here in the first field it is taking as Area and select the field values and next it has to perform the clicking “+” button and then it has to select the another field from the second field
Observed issue:
Here it is always selecting the first field value only instead of 2,3,4,…..


Could you please share your ideas please let me know if u have any better solution for this
Thanks,
Venkat.Batchu


RE: QTP 9.5 - Select an element in a table - SAKDOSS - 07-30-2009

Thank you very much QTPKing.

I'm using a JTable so I modify a little bit your script (I also changed the For loops into While loops).

Code:
'String which enable to identify the line
id = "090701224501893r"

'Column where we will search id
colIdLabel = "FIX.4.2"

'Column of the expected value
colExLabel = 8

If JavaWindow("Log Message").JavaTable("MessageTable").Exist Then
    nbCol = JavaWindow("Log Message").JavaTable("MessageTable").GetROProperty("cols")

    'We are trying to find 2 columns (one for the id and one for the expected value)
    nbFindCol = 0
    
    'Find the expected columns
    i = 0
    While nbFindCol<2 and  i<nbCol
        If  JavaWindow("Log Message").JavaTable("MessageTable").GetCellData(0, i) = colIdLabel Then
            colIdNum = i
            nbFindCol = nbFindCol +1
        End If
        If  JavaWindow("Log Message").JavaTable("MessageTable").GetCellData(0, i) = colExLabel Then
            colExNum = i
            nbFindCol = nbFindCol +1
        End If
        i = i+1
    Wend
    If nbFindCol <> 2 Then
        msgbox "Error : one of the column has not been found"
    Else
        nbRow = JavaWindow("Log Message").JavaTable("MessageTable").GetROProperty("rows")

        'Find the expected row
        i = 0
        found = false
        While found = false and i<nbRow
            If JavaWindow("Log Message").JavaTable("MessageTable").GetCellData(i,colIdNum) = id Then
                rowExNum = i
                found = true
            End If
            i = i + 1
        Wend

        msgbox JavaWindow("Log Message").JavaTable("MessageTable").GetCellData(rowExNum,colExNum)
    End If
Else
    msgbox "The Java Table doesn't exists"
End If



RE: QTP 9.5 - Select an element in a table - supputuri - 07-30-2009

that's great SAKDOSS