cancel
Showing results for 
Search instead for 
Did you mean: 

How to get child elements count in a web page.

NaveenRPA
Level 4
I am trying to extracting table data in a webpage but that table is not in <table>  tag it is in <div> tag. If i want to extract table data first i need get child count so that i can loop rows and i can extract. in javascript we can use document.querySelector("#example > tbody").childElementCount to get child elements.
example html:
<div class="table">
<div class="thead">
<div class="column-1">Colum1</div>
<div class="column-2"">Colum2</div>
</div>
<div class="tbody">
<div class="trow-1">

<div class="row-1">Row1</div>
<div class="row-2">Row2</div>
</div>
<div class="trow-2">
<div class="row-1">Row1</div>
<div class="row-2">Row2</div>
</div>

</div>
</div>
How can i get `tbody` child elements count.

------------------------------
naveen kumar
------------------------------
1 REPLY 1

Hi Naveen,

You can get the child element counts from this XML once you pull the source code from the web page like what you've provided using 'Utility - XML' VBO which is available in the VBO folder of your Blue Prism installation folder.

First you need to use the 'Get Elements By XPath' action by passing the XML input along with the XPath expression: "//div[@class=" & """" & "tbody" & """" & "]" (in case you are setting it via Blue Prism). If you are setting it as an initial value in some data item and passing it then use: //div[@class="tbody"] .

This action will give you a collection let say, 'Elements' consisting of child element details within div tags having the class attribute as 'tbody'. Next, you can loop within the collection and then again use 'Get Elements By XPath' action with the XML input as "div" & [Elements.Inner XML] & "/div" and XPath expression as "//div" and store the value in a collection called 'Sub Elements'.

Now you need to loop within 'Sub Elements' collection and increment the count value. The initial value of this count value should be 0.

By the end of the entire workflow, it will return you the total child count.

Below is the sample workflow:

333.png

334.png
336.png

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please provide a big thumbs up so that the others members in the community having similar problem statement can track the answer easily in future.

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Technical Business Analyst,
WonderBotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------