QTP blog reader Abhijeet has asked here for a way to get total no of rows irrespective of whether the rows are visible or not. I have also faced this problem once while working on a Siebel Application and have written a small piece of code for it.
I would like to reproduce the same code here for the benefit of QTP community. Please make necessary changes according to the needs of your application.
' Name: gf_CountTotalRows ' Description:This function counts the total no of rows irrespective of whether the rows are visible or not ' Created By:Ankur Jain ' Variables:sRecordCounter,arrRecordCounter,str,plus,sTotal_Rows ' Environment Variable:Row_Count ' Parameters:uiname '**************************************************** Public Function gf_CountTotalRows(uiname) 'Variable will contain the (statement) firstset of current no of records sRecordCounter=SiebApplication("micclass:=SiebApplication").SiebScreen("micclass:=SiebScreen").SiebView("micclass:=SiebView").SiebApplet("micclass:=SiebApplet","uiname:="&uiname).RecordCounter 'Splitting the variable to get the "+ "sign arrRecordCounter = Split(sRecordCounter) 'Storing the 4 member of array(ie the member which contains the + sign) str=arrRecordCounter(4) 'Capturing the "+" sign plus=Right(str,1) 'Loop to navigate till the last rowset Do while plus ="+" SiebApplication("micclass:=SiebApplication").SiebScreen("micclass:=SiebScreen").SiebView("micclass:=SiebView").SiebApplet("micclass:=SiebApplet","uiname:="&uiname).SiebList("micclass:=SiebList").NextRowSet sRecordCounter=SiebApplication("micclass:=SiebApplication").SiebScreen("micclass:=SiebScreen").SiebView("micclass:=SiebView").SiebApplet("micclass:=SiebApplet","uiname:="&uiname).RecordCounter arrRecordCounter = Split(sRecordCounter) str=arrRecordCounter(4) plus=Right(str,1) Loop 'sRecordCounter will contain the last set of current visible no of records sRecordCounter=SiebApplication("micclass:=SiebApplication").SiebScreen("micclass:=SiebScreen").SiebView("micclass:=SiebView").SiebApplet("micclass:=SiebApplet","uiname:="&uiname).RecordCounter arrRecordCounter = Split(sRecordCounter) ' sTotal_Rows will contain the Total No of records in string format sTotal_Rows=arrRecordCounter(4) Environment.Value ("Row_Count") = sTotal_Rows 'Finally to navigate back to the first row set 'On error resume next 'The next statement works only when the no of rows are greater than visible no of rows if (Row_Count > 5) then SiebApplication("micclass:=SiebApplication").SiebScreen("micclass:=SiebScreen").SiebView("micclass:=SiebView").SiebApplet("micclass:=SiebApplet","uiname:="&uiname).SiebList("micclass:=SiebList").FirstRowSet End if End function
Related: Tips with QTP
Tips with Siebel Add-in
Tips with Oracle/Java Add-in
If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS Feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.
Hi
How to count the rows(emails)in webtable.Am selcting webtable only one column will be added.plz post the code
Hi
This is Boby. I am new to this blog. I had a problem in “How to count total no of rows when all rows are not visible “. I am using QTP 10.0 and the default Add-ins like Active X,Visual Basic and Web Addins.please send me the code if possible.Appreciate your response.
@Anon:
Here is the algo in a nutshell:
1. Get the row count using GetRoProperty (We will call this as rowcount)
2. Using a loop check for the existence for static heading2. Exit the loop as soon as you get the matching string.
3. Note the position of static heading2 using a variable.
4. Say it occurs at nth position
5. The total no of rows below static heading1 would be (n-2) and total no of rows below static heading2 would be (rowcount-n)
Please use QTP Forums for further questions
Thanks!
Hi Ankur
Recently i have faced an interview and there they asked a question – On a web page there is one table of one column.
the first row has one static heading and following rows have some dynamic values. again after these values there is another row with the static heading 2. again a set of rows containing dynamic values.
Question is to count the no of rows under the respective headings individually.
Could you please explain me how to do that.
Thanks
Hi raju,
can I get your e-mail id. I have so many doubts in QTP frame works. I would like to ask you.
Thanks in advance.
Hi,
I am Ram, Can some one tell me, how to get the row count for the WinObject? I donot see the Rowcount property for WinObject(“TableView”). I am working on outlook 2007 testing.
any help is appreciated.
Regards
Ram
@Anon: As I have explained above. It is because of the fact that all rows were not visible and and were paginated.
Otherwise QTP too has a straightforward way of counting rows
why u need so much of code for finding the rowcount ,
Just migrate to WinRunner u could do it tbl_get_rows_count 🙂
Hi
Gopal What u need
tell me
9866600371
Hi
How to add new rows in the datatable?
please help
bye..
ksubbaraju6@gmail.com
HI
This raju from leading @MNC,
regrading any QTP doubt and Testing information tell me
I will solve to u.
if ur in Hyderabad contact me
9866600371
I am expert in Frame works and Descritpive programming
bye..
Hi, dis is gopalreddy iam very intreststed by knowing the qtp information plz cooparate me
This can be used only if application hasd the records in a table format. But my application has the records in a pane where it is not recognised as a table but as a object.
How can this be tackled?
Is there any facility like adding the new window ‘s objects to the Object Repository during the run time