When running a script which processes tables in textframes, offset tables are not detected. If you have a text frame which contains 5 tables, of which are only 3 visible, and 2 are offset. The script detects only 3. You can test this using ...
Uwe Laubender commented
I think, that's no bug. But I'm not sure…
Provided your allPageItems contains a text frame and that text frame is showing overset and therefore is showing only 3 out of 5 tables, then the tables.length value is only 3.
If you are asking differently:
you'd get 5 as result.
if your tables are created with that story.