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.
Get the count of the child div tags
-
- Posts: 1
- Joined: Wed Jan 22, 2014 2:17 pm
Get the count of the child div tags
You do not have the required permissions to view the files attached to this post.
Re: Get the count of the child div tags
Hi Sarathsp23,
That's strange. In order to retrieve all child "DivTags" from your "DivTag" use FindDescendants<DivTag>()
E.g.:
Regards,
Robert
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)
};
Robert
Re: Get the count of the child div tags
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).
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Get the count of the child div tags
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
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
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
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
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
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?
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
I am answering my own questions... FindChildren instead of FindDescendant (I have 12 now).
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Get the count of the child div tags
Hi,
Do you need any further help?
Regards,
Robert
Do you need any further help?
Regards,
Robert