count rows in Table of HTML is not working

Ranorex Spy, Recorder, and Studio.
yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

count rows in Table of HTML is not working

Post by yoad » Tue Jul 02, 2013 2:54 pm

'//////////////////////////////////////////////////////////////////////////////
'
' This file was automatically generated by RANOREX.
' Your custom recording code should go in this file.
' The designer will only add methods to this file, so your custom code won't be overwritten.
' http://www.ranorex.com
'
'//////////////////////////////////////////////////////////////////////////////

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Drawing
Imports System.Threading
Imports WinForms = System.Windows.Forms

Imports Ranorex
Imports Ranorex.Core
Imports Ranorex.Core.Testing

Namespace Easyadmin

    Public Partial Class Operational_CurrentlyConsumedLicenses

        ''' <summary>
        ''' This method gets called right after the recording has been started.
        ''' It can be used to execute recording specific initialization code.
        ''' </summary>
        Private Sub Init()
            ' Your recording specific initialization code goes here.
        End Sub

        Public Sub TestGridHTML()
        	Dim repo As EasyadminRepository = EasyadminRepository.Instance
        	Dim webDocument As WebDocument ="/dom[@domain='localhost:7019']"
        
    	dim rows as Integer=repo.OpenLMEasyAdmin2.Table.Find(".//div[@id~'gridview\d\d\d\d']/table/tbody/tr[2]").Count
        	
        	
            
            
            If(rows>1) Then
         
        	' List all elements of a table
        	
        	For Each row As TrTag In repo.OpenLMEasyAdmin2.Table.Find("./tbody/tr[2]")
        		
        		Dim rowInfo As String = ""
        		
        		Dim rowNameCell As TdTag = row.FindSingle("./td[2]")
          

        		
        		'Get all cells from the row
        		rowInfo += "All Cells: "
        		For Each cell As DivTag In row.Find("./td/div")
                     
                    if(cell.InnerText.Length>1) Then
        			report.Info(cell.InnerText() )
                    Else
                    report.Failure(cell.InnerText())
        			End If
        			' Move the mouse to each cell element
        			cell.MoveTo()
        			' Set css style
        			cell.SetStyle("background-color", "#33ff00")
        			
        		Next
        		
        	

        	Next
        	
         	End If
        End Sub

    End Class
End Namespace

but it is not counting rows why?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: count rows in Table of HTML is not working

Post by krstcs » Tue Jul 02, 2013 3:48 pm

Without seeing the structure of your AUT, it will be hard for any of us to help you.

I would guess though that the XPath in your count line may be the issue. It appears you are looking for the rows in a table inside another table.
Shortcuts usually aren't...

yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

Re: count rows in Table of HTML is not working

Post by yoad » Tue Jul 02, 2013 5:40 pm

I have one Table HTML and i think that code
" dim rows as Integer=repo.OpenLMEasyAdmin2.Table.Find(".//div[@id~'gridview\d\d\d\d']/table/tbody/tr[2]").Count "

that code is not work because code do not count rows...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: count rows in Table of HTML is not working

Post by Support Team » Wed Jul 03, 2013 1:04 pm

Hello,

The problem seems to be the path in the Find() method.
I don't know how the structure of your repository looks like, but it should be enough if you just count the "TR" tags in the TBody tag as shown in my example below.
Repository.png
Repository.png (2.96 KiB) Viewed 1938 times
In order to count the rows I used the following code:
Dim rows As Integer = repo.HTMLTables.Table.TBody.Find("TR").Count
Regards,
Bernhard
.
Image

yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

Re: count rows in Table of HTML is not working

Post by yoad » Wed Jul 03, 2013 1:56 pm

Hello Bernhard and Support team
I try it before you said but it did not work ,the problem that I have 2 tr in table -tr empty and tr with data
How do I solve problem?
thank you
Regards,

yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

Re: count rows in Table of HTML is not working

Post by yoad » Thu Jul 04, 2013 8:39 am

Hello again,I add snapshot file of Table HTML In Grid
thank you
Attachments
TableofHTMLInGrid.rxsnp
(365.04 KiB) Downloaded 171 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: count rows in Table of HTML is not working

Post by Support Team » Fri Jul 05, 2013 12:07 pm

Hello,

Thank you for the snapshot file.
The TR-tag contains only the header cells (TH-tags).
You can just decrease the count value with 1.
Dim rows As Integer = repo.HTMLTables.Table.TBody.Find("TR").Count  - 1
Regards,
Bernhard
.
Image

yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

Re: count rows in Table of HTML is not working

Post by yoad » Sun Jul 07, 2013 8:05 am

Hello Bernhard
I tried with it
but it is not working

'HTMLTables' is not a member of 'Easyadmin.Easyadmin.EasyadminRepository'. (BC30456) - C:\Users\Yoad\Documents\Ranorex\RanorexStudio

I think also try
Dim rows as Integer=repo.OpenLMEasyAdmin2.Table.Find(".//div[@id~'gridview\d\d\d\d']/table/tbody/tr[2]").Count-1

but it is not working

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: count rows in Table of HTML is not working

Post by Support Team » Mon Jul 08, 2013 3:40 pm

Hello,

"HTMLTables" is an app folder in my example Repository. Please take a look at the screenshot in one of my previous posts.
I added the screenshot of my Repository because I don't know how your repository looks like.
The error message in your post means that there is no Item in your Repository with the name "HTMLTables".
What is the RanoreXPath of your Repository item "repo.OpenLMEasyAdmin2.Table"?
Is it possible to post a little example project or your repository in order to analyze the issue?
Thank you!

Regards,
Bernhard
.
Image

yoad
Posts: 39
Joined: Sun May 26, 2013 9:08 am

Re: count rows in Table of HTML is not working

Post by yoad » Tue Jul 09, 2013 5:22 am

Hello Bernhard
it appears here

I sent Attachment before 5 days...
please see in quotes

It is not enough?

Regards,
Yoad

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: count rows in Table of HTML is not working

Post by Support Team » Wed Jul 10, 2013 2:02 pm

Hello,

I would need the repository file, but you have sent the Ranorex snapshot file.
However, as workaround you can try to use the following code:
Element myElement = "/dom[@domain='localhost:7019']//div[#'gridview-1266']/table/tbody";
int count = myElement.Find("TR").Count - 1;
In that case I don't need your repository file.
This should work as well.

Regards,
Bernhard
.
Image