New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Absent Member.
Absent Member.
7715 views

QTP - JavaTable row selection?

Jump to solution
Hi all,

I'm relatively new to QTP and have only really used it to record very specific (controlled) regression type testing. The problem that I constantly run into is that if the data is manipulated in anyways, my recordings which are set to select row X will now be selecting the incorrect row.

Is there a way to have it select a row based on a specific criteria? i.e. "Select the row that has name TESTER1" with one of the columns named "name"? This is all on a Java built Platform.

Thanks!
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.
You can get value of n using the below line of code.

n = object.RowCount

Here the object is JavaTable.

Thanks..
Arpan

View solution in original post

15 Replies
Highlighted
Absent Member.
Absent Member.
You can use GetCellData method.

object.GetCellData (Row, Column)

Here the object is of type JavaTable. Row and Column are the values of the cell in the table from where you want to get the data.

So the code will be something like this.

For i = 1 TO n
str_name = object.GetCellData (n, Column)
If str_name = "TESTER1" Then
Highlighted
Absent Member.
Absent Member.
Hrm, that looks like it would work! I guess I'd just write that up into the function library and make a function call in my action list then.

Is there a way to get the total number of rows in a table? (Sorry if these are simple answers, as I stated, I haven't had much time to use QTP at a higher level).
0 Likes
Highlighted
Absent Member.
Absent Member.
You can get value of n using the below line of code.

n = object.RowCount

Here the object is JavaTable.

Thanks..
Arpan

View solution in original post

Highlighted
Absent Member.
Absent Member.
Again, sorry for being seemingly completely new to this (no VB background either, go figure).

So would I write my function to look like this:

Function searchRow( windowStr, tableStr, searchStr)
Dim i, n, str_name
n = JavaWindow(windowStr).JavaTable(tableStr).RowCount
For i = 1 TO n
str_name = JavaWindow(windowStr).JavaTable(tableStr).GetCellData (n, Column)
If str_name = "TESTER1" Then
JavaWindow(windowStr).JavaTable(tableStr).SelectRow(i)
End If
Next
End Function

Thanks for your continued help!
0 Likes
Highlighted
Absent Member.
Absent Member.
Whoops, let me fix that typo:



Again, sorry for being seemingly completely new to this (no VB background either, go figure).

So would I write my function to look like this:

Function searchRow( windowStr, tableStr, searchStr, columnStr)
Dim i, n, str_name
n = JavaWindow(windowStr).JavaTable(tableStr).RowCount
For i = 1 TO n
str_name = JavaWindow(windowStr).JavaTable(tableStr).GetCellData (i, columnStr)
If str_name = searchStr Then
JavaWindow(windowStr).JavaTable(tableStr).SelectRow(i)
End If
Next
End Function

Thanks for your continued help!
0 Likes
Highlighted
Absent Member.
Absent Member.
The code ok except in

str_name = JavaWindow(windowStr).JavaTable(tableStr).GetCellData (n, Column)

you need to replace the value of column with the no. If the name is available in column 1 of the table then your code will look like..

str_name = JavaWindow(windowStr).JavaTable(tableStr).GetCellData (n, 1)

Thanks..
Arpan
Highlighted
Absent Member.
Absent Member.
Ah okay so it doesn't go by column Name but actually column number.

So when I actually put this into my function library, I can call it anytime from my test procedure by making a call to the function like this?

searchRow( "JavaWindow_1", "Table_2", "XXXXX", 3)

and this should basically search through find the string XXXXX in column 3, and select the first result it finds? Thanks a ton. I'll try this out asap.
0 Likes
Highlighted
Absent Member.
Absent Member.
I just tested this out, and when I tried to call the function using the below formatting I get an error upon save stating:
"Cannot use parantheses when calling a Sub"

Is there something I'm missing?
0 Likes
Highlighted
Absent Member.
Absent Member.
Try with this.

str_name = JavaWindow(windowStr).JavaTable(tableStr).GetCellData n, 1

When you are using single parameter you can use parenthese but for multiple you need to omit that.

Thanks..
Arpan
Highlighted
Absent Member.
Absent Member.
Whoops, tried it again without the parantheses around the variables and the error went away. Loading DB and testing now *crosses fingers*
0 Likes
Highlighted
Absent Member.
Absent Member.
hrm,

it calls the function okay now, but I get an error at this line:

n = JavaWindow(windowStr).JavaTable(tableStr).RowCount


Error msg:
The operation cannot be performed

Function file: C:\Program Files\HP\QuickTest Professional\Tests\SearchRow_GCC.qfl
Line (3): " n = JavaWindow(windowStr).JavaTable(tableStr).RowCount()".

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.