A table sits in a paragraph. When a table breaks across frames, each line of the table's paragraph contains the part of the table that sits in a frame, and each line is in the first paragraph of each frame. The part of the table that sits in the frame you selected is in your selected frame's first paragraph.
But you don't have direct access to that part. To determine which cells are in the selected frame, you have to get a reference to the whole table, get all the cells, and cycle through them, checking whether a cell's insertion point's parent text frame is your selected frame. (This is problematic with overset cells, so you should check that first.)
Like this:
frame = app.selection[0];
// Get all the cells in the table
cells = frame.paragraphs[0].tables[0].cells.everyItem().getElements();
sel = [];
// Collect the cells that are in the frame
for (i = 0; i < cells.length; i++) {
if (cells[i].insertionPoints[0].parentTextFrames[0] == frame) {
sel.push (cells[i]);
}
}
// Display the content of the selected cells
for (i = 0; i < sel.length; i++) {
$.writeln (sel[i].contents);
}
P.