Page 1 of 1

Get the count of the child div tags

Posted: Wed Jan 22, 2014 2:29 pm
by Sarathsp23
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.

Re: Get the count of the child div tags

Posted: Tue Jan 28, 2014 3:18 pm
by rprehm
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

Re: Get the count of the child div tags

Posted: Fri Feb 21, 2014 7:16 pm
by kthomp
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).

Re: Get the count of the child div tags

Posted: Mon Feb 24, 2014 5:33 pm
by Support Team
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

Re: Get the count of the child div tags

Posted: Tue Feb 25, 2014 4:00 pm
by kthomp
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

Re: Get the count of the child div tags

Posted: Tue Feb 25, 2014 4:01 pm
by kthomp
oops - ignore "you got past breakpoint" in error output (I deleted that from the exception and didn't re-run)

Re: Get the count of the child div tags

Posted: Tue Feb 25, 2014 5:48 pm
by kthomp
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?

Re: Get the count of the child div tags

Posted: Tue Feb 25, 2014 5:57 pm
by kthomp
I am answering my own questions... FindChildren instead of FindDescendant (I have 12 now).

Re: Get the count of the child div tags

Posted: Wed Feb 26, 2014 3:23 pm
by Support Team
Hi,
:)
Do you need any further help?

Regards,
Robert