Code Table HTML works only on a single line in the grid

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

Code Table HTML works only on a single line in the grid

Post by yoad » Sun Aug 04, 2013 9:19 am

Hello,
Code Table HTML works only on a single line in the grid
how it does work on a all lines?
I prefer to work without Repository

Code: Select all

            dim repo As EasyadminRepository = EasyadminRepository.Instance
        	Dim someTableTag As TableTag
        	someTableTag = "/dom[@domain='localhost:7019']//div[@id~'gridview-\d\d\d\d']/table"
        	
        	
        	
        	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
'             Dim rows As Integer = repo.HTMLTables.Table.TBody.Find("TR").Count  - 1
             Dim rows As Integer=someTableTag.Find(".//tbody/tr[2]").Count-1
'             If(rows>1) Then
         
        	' List all elements of a table
        	
        	For Each row As TrTag In someTableTag.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.Warn(cell.InnerText())
'        			End If
        			' Move the mouse to each cell element
        			cell.MoveTo()
        			' Set css style
        			cell.SetStyle("background-color", "#33ff00")
        			
        		Next
        		
        	

        	Next

        End Sub
    End Module
kind regards,
Yoad

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

Re: Code Table HTML works only on a single line in the grid

Post by Support Team » Tue Aug 06, 2013 1:33 pm

Hello,

Could you please post a little example solution using an example website?
I guess the problem is that you are only searching the second row (tr[2]) in your table. I don't know how your application looks like, but in general you can try to create a loop and increase the index within the "TR" tag.

Regards,
Bernhard
.
Image

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

Re: Code Table HTML works only on a single line in the grid

Post by yoad » Wed Aug 07, 2013 9:31 am

hello Bernhard,
I have tr empty and tr with data
then I wrote tr[2]
I hope that website is working for you
http://localhost:7019/EasyAdmin2/index.html

i choose start-->Licenses

Kind regards,
Yoad

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

Re: Code Table HTML works only on a single line in the grid

Post by yoad » Wed Aug 07, 2013 1:46 pm

hello again,
I did spy and I add 2 sanpshot files

kind regards,
Yoad
Attachments
TableofHTMLInGrid.rxsnp
(365.04 KiB) Downloaded 177 times
TableOFHTMLInGrid2.rxsnp
(415.96 KiB) Downloaded 172 times

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

Re: Code Table HTML works only on a single line in the grid

Post by Support Team » Thu Aug 08, 2013 12:50 pm

Hello,

Could you please describe in detail what you are trying to do?
Do you want to iterate through each div tag inside your table's tr tags?
If yes you can use the following code:
' ....
For Each row As TrTag In someTableTag.Find("./tbody/tr")

				For Each cell As DivTag In row.Find("./td/div")
					'
					'                    if(cell.InnerText.Length>1) Then
					'                 report.Info(cell.InnerText() )
					'                    Else
					'                    report.Warn(cell.InnerText())
					'                 End If
					' Move the mouse to each cell element
					cell.MoveTo()
					' Set css style
					cell.SetStyle("background-color", "#33ff00")
					
				Next
				
			Next
Regards,
Markus
.
Image

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

Re: Code Table HTML works only on a single line in the grid

Post by yoad » Tue Aug 13, 2013 12:46 pm

Hello,
I tried your code but it does not work
and I got error message

Ranorex Test Report
Log LevelDebugInfoWarnErrorTest Result Time Level Category Message
2013/08/13 14:38:58.929 ERROR Module No element found for path './td'

then I must write it because I have empty tr and tr with data

For Each row As TrTag In someTableTag.Find("./tbody/tr[2]")

For Each cell As DivTag In row.Find("./td[2]/div")

it working for me but just for singe line in the grid

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

Re: Code Table HTML works only on a single line in the grid

Post by Support Team » Fri Aug 16, 2013 5:35 pm

Hi,

You are getting the error since the first TR tag, representing the header of the grid, doesn't include a TD tag.
You need to add a mechanism that handles this case, in the first iteration the child elements needs to be handled differently.

Regards,
Markus
.
Image

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

Re: Code Table HTML works only on a single line in the grid

Post by yoad » Tue Aug 20, 2013 2:14 pm

Hello Markus,
You mean that I need to use method "Relationship Operators" in Ranorex User Guide ?

Regards,
Yoad

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

Re: Code Table HTML works only on a single line in the grid

Post by Support Team » Thu Aug 22, 2013 4:50 pm

Hi Yoad,

I meant that the header row (first tr tag) has no div tags and therefore needs to be handled differently.
You could use a code similar to the following one:
Dim headerName as String = "x-grid-header-row"
			Dim className As String = ""
			
			For Each row As TrTag In someTableTag.Find("./tbody/tr")
				
				className = row.Element.GetAttributeValueText("Class")
				
				if className<>headerName Then
					For Each cell As DivTag In row.Find("./td/div")
						'
						'                    if(cell.InnerText.Length>1) Then
						'                 report.Info(cell.InnerText() )
						'                    Else
						'                    report.Warn(cell.InnerText())
						'                 End If
						' Move the mouse to each cell element
						cell.MoveTo()
						' Set css style
						cell.SetStyle("background-color", "#33ff00")
						
					Next
					
				End If
				
			Next
Regards,
Markus
.
Image

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

Re: Code Table HTML works only on a single line in the grid

Post by yoad » Sun Aug 25, 2013 2:08 pm

Hello Markus,
Thank you
I give you feedback

Kind Regards,
Yoad