Get the count of the child div tags

Class library usage, coding and language questions.
Sarathsp23
Posts: 1
Joined: Wed Jan 22, 2014 2:17 pm

Get the count of the child div tags

Post by Sarathsp23 » Wed Jan 22, 2014 2:29 pm

I am trying to find the number of immediate div tags present inside the main div tag
As shown in the attached screen shot, I am trying to find the total number immediate child div tags for the parent div "MacroTableBody"

I have tried the FindChild<T>() and FindDescedents<T>(), however I am not getting the total count of child div tags.
Please let me know how to find the immediate child elements count for a div tag.
Attachments
Capture.PNG
Capture.PNG (30.73 KiB) Viewed 4000 times

User avatar
rprehm
Posts: 24
Joined: Tue Dec 17, 2013 6:43 pm

Re: Get the count of the child div tags

Post by rprehm » Tue Jan 28, 2014 3:18 pm

Hi Sarathsp23,

That's strange. In order to retrieve all child "DivTags" from your "DivTag" use FindDescendants<DivTag>()
E.g.:

Code: Select all

 public void getCountOfDivTag()
        {
        	//Div tag which holds another 5 divTags
        	var someDivTag = repo.W3SchoolsOnlineWebTutorials.SomeDivTag;
        	//Create list of div tags
        	IList<DivTag> divList = someDivTag.FindDescendants<DivTag>();
        	//Output the count of the div tags
        	Report.Info("Div tag count: " + divList.Count)
};
Regards,
Robert

kthomp
Posts: 6
Joined: Thu Feb 20, 2014 4:26 pm

Re: Get the count of the child div tags

Post by kthomp » Fri Feb 21, 2014 7:16 pm

Is this solution supposed to give the total ROWs or COLUMNs in the MacroTableBody example? I tried this and divList.Count = 3 instead of the expected 12 (there are 3 columns in this table and 12 rows).

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

Re: Get the count of the child div tags

Post by Support Team » Mon Feb 24, 2014 5:33 pm

Hi kthomp,

It depends on your application. Are you also testing a website with Ranorex? Can you please send a snapshot file in order to provide more information about your issue?
Thank you!

Regards,
Bernhard
.
Image

kthomp
Posts: 6
Joined: Thu Feb 20, 2014 4:26 pm

Re: Get the count of the child div tags

Post by kthomp » Tue Feb 25, 2014 4:00 pm

I am actually from the same company as Sarath, the original poster, so my application is the same (web app).

The code I am running now is:

DivTag dt = (DivTag)objEle;
IList<DivTag> _dTrows = dt.FindDescendants<DivTag>();


var _dTCounts = _dTrows.Count();
int _dTexpectedRowCount;
int.TryParse(strVerificationData.Trim(), out _dTexpectedRowCount);


if (_dTCounts != _dTexpectedRowCount)
{
//throw new Exception("Verification Failed >> Actual Number of Rows :" + _dTrows + "Expected
Number of Rows :" + _dTexpectedRowCount);
throw new Exception("_dtrows = " + _dTrows + " _dTCounts = " + _dTCounts +
"_dtExpectedRowCount = " + _dTexpectedRowCount);
}

In addition, I am going to have to count only the lines that are highlighted (zero) at this point. But, I was first interested in coming up with the correct total number of rows and then deal with figuring out how to tell if any are selected. **note - my exception message is obviously being used for debugging, not as an error**

This is my actual error output:
Error # -2146232832 Exception from VerifyNoRowsSelected Keyword : you got past breakpoint: _dtrows = System.Collections.Generic.List`1[Ranorex.DivTag] _dTCounts = 3_dtExpectedRowCount = 0 at AllScriptsTestAutomationFramework.Framework.RanorexWebActions.VerifyNoRowsSelected(String strObject, String strVerificationData) in c:\AllScriptsTestAutomationFramework\AllScriptsTestAutomationFramework\Framework\RanorexWebActions.cs:line 2173

kthomp
Posts: 6
Joined: Thu Feb 20, 2014 4:26 pm

Re: Get the count of the child div tags

Post by kthomp » Tue Feb 25, 2014 4:01 pm

oops - ignore "you got past breakpoint" in error output (I deleted that from the exception and didn't re-run)

kthomp
Posts: 6
Joined: Thu Feb 20, 2014 4:26 pm

Re: Get the count of the child div tags

Post by kthomp » Tue Feb 25, 2014 5:48 pm

I have gotten past the previous error - my xpath was wrong. :(

I am now returning a count of 48 (ALL descendants). Is it possible to specify only descendants one level down, or maybe all descendants of a certain class?

kthomp
Posts: 6
Joined: Thu Feb 20, 2014 4:26 pm

Re: Get the count of the child div tags

Post by kthomp » Tue Feb 25, 2014 5:57 pm

I am answering my own questions... FindChildren instead of FindDescendant (I have 12 now).

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

Re: Get the count of the child div tags

Post by Support Team » Wed Feb 26, 2014 3:23 pm

Hi,
:)
Do you need any further help?

Regards,
Robert
.
Image