Skip to content
Advertisement

Cypress cant seem to find any elements inside the iframe

I am trying to access elements within my iframe following the tips listed in this article here, but for some reason cypress cannot seem to find anything in the iframe.

Here is my test code

JavaScript

And this is my iframe

<iframe data-cy="iframe" title="iframe" style={{ height: '100%', width: '100%' }} src={url} />

Finally this is what I have in my cypress.json

JavaScript

This is based on the above article. Not sure where I am going wrong.

Advertisement

Answer

You can use a plugin called cypress-iframe. After installation, go to cypress/support/commands.js and add the following:

JavaScript

In your test you can directly use :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement