Hi @SarahChap ,
you say: "In my InDesign templates, there are Rectangle ([object Rectangle]) items, that further includes some TextFrames (more than one). "
How do you know that? Did you build the template?
I'd try that with InDesign Desktop first.
The rectangle should contain a group item that itself includes all other frames.
Best make a sample InDesign document available with one rectangle that includes the text frames.
Attach the document to your reply here in the forum.
Or do a screenshot when the document is open in InDesign Desktop.
With the rectangle selected and the Layers panel open showing all its contents like that:
From my German InDesign 184.108.40.206 on Windows 10:
In this case, the following code:
will return 5, 1 group and 4 text frames.
( Adobe Community Expert )