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:
let iframe = document.getElementById('iframe'); // L'iframe
let win = iframe.contentWindow; // L'oggetto window dell'iframe
// L'oggetto document dell'iframe
let doc = iframe.contentDocument ? iframe.contentDocument: iframe.contentWindow.document;
// Un elemento nell'iframe
let test = doc.querySelector('.test');