Anish Krishnan
Anish Krishnan

Reputation: 63

How to get hidden iframe element in Cypress? And how to write in it?

I want to get/idenify hidden iframe element in Cypress and write something in there, like a text.

<div class="tox-edit-area">
  <iframe id="tiny-react_36495184831607144646798_ifr" frameborder="0" 
     allowtransparency="true" title="Rich Text Area. Press ALT-0 for       
     help." class="tox-edit-area__iframe" __idm_frm__="1483" 
     __idm_id__="362838018">
  </iframe>
</div>

error fetched https://i.sstatic.net/v4wub.png

Upvotes: 0

Views: 523

Answers (1)

Alapan Das
Alapan Das

Reputation: 18634

1.Go to cypress/support/command.js and write:

Cypress.Commands.add('getIframe', (iframe) => {
    return cy.get(iframe)
        .its('0.contentDocument.body')
        .should('be.visible')
        .then(cy.wrap);
})

2.In the tests write:

cy.getIframe('.tox-edit-area__iframe').clear().type('Demo Text')

Upvotes: 1

Related Questions