I can't see why cy.iframe('iframe:first')
would not work, but if you have independent parent elements, e.g the <form>
element mentioned, it's possible to pre-select the correct parent and apply cy.iframe()
using that parent as "root" element.
The .within()
command changes the root element:
cy.visit('/', {
onBeforeLoad(win) {
cy.stub(win.console, 'log').as('consoleLog')if you
}
})
cy.get('@consoleLog').should('be.calledWith', 'Iframe Loaded')
cy.get('iframe').eq(0)
.parent()
.within($iframeParentElement => {
cy.iframe()
.should('have.length', 1) // expected <body> to have a length of 1 ✅
.find('input#data')
.should('have.length', 1) // expected <input#data> to have a length of 1 ✅
})
I also added a check on the "IFrame Loaded" console message that Tokenex emits, so as to delay <iframe>
commands until loading is complete.