Un iframe non è altro che un documento all'interno di un altro documento. Per questo motivo esiste una procedura specifica per accedere ai suoi contenuti con JavaScript.
La procedura è la seguente:
'use strict';
const iframe = document.getElementById( 'iframe' ); // L'iframe
const win = iframe.contentWindow; // L'oggetto window dell'iframe
// L'oggetto document dell'iframe
const doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document;
// Un elemento nell'iframe
const test = doc.getElementById( 'test' );