Count child elements

Hello, im new to Kantu.

I want to count the total child elements within a specific div id., and store it into a variable.

Example

<div id="maindiv">
    <div id="innerdiv">
    </div>
    <div id="innerdiv">
    </div>
    <div id="innerdiv">
    </div>
    <div id="innerdiv">
    </div>
    <div id="innerdiv">
    </div>
<div>

I want to store a variable with the total “innerdiv” count within the “maindiv” div . In this example would be 5.

I ve spent a lot of time trying different stuff but with no success, I would appreciate any help.

Thanks!

Maybe sourceSearch + regex? Search and Extract page source code - Selenium IDE Commands Tutorial

sourceSearch | innerdiv | result

The sourceSearch command It does not work on the DOM, but directly on the HTML page. But often that does not matter.

1 Like

Hey Plankton, thanks for you reply.

Unfortunately in my case I need to work on the DOM, because the full site is generated by javascript, there are no HTML tags to parse in the source.

Any other ideas? I have been stuck in my project for 2 days because of this, I need to count the childs of a dynamic div in order to advance :frowning:

I ve seen some stackoverflow posts talking about this, working with selenium. They are using xpath property “Count”.

Problem is I dont know how to use it, or if it is even possible with Kantu.

A code example with my issue example would be really appreciated if anyone knows how to do it