Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing iframe within iframe? #15268

Closed
bahunov opened this issue Mar 1, 2021 · 1 comment
Closed

Accessing iframe within iframe? #15268

bahunov opened this issue Mar 1, 2021 · 1 comment

Comments

@bahunov
Copy link

bahunov commented Mar 1, 2021

Current behavior

How do I access iframe wihthin an iframe?

I have tried it all:

const getIframeBody = () => {
    // get the iframe > document > body
    // and retry until the body element is not empty
    return cy
    .get('frame[name="login"]')
    .its('0.contentDocument.body').should('not.be.empty')
    // wraps "body" DOM element to allow
    // chaining more Cypress commands, like ".find(...)"
    // https://on.cypress.io/wrap
    .then(cy.wrap)
  }
  
 getIframeBody()
    .find('frame[name="leftbar"]')

Not working..

Test code to reproduce

Following css:
image

Some elements are within the second iframe name="leftbar"

Versions

6.5.0

@jennifer-shehane
Copy link
Member

Your HTML is using <frame> elements, which are no longer supported by browsers, so I wouldn't expect Cypress to support this use case. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame

We're currently working on an API for iframe support: #136

With <iframe> you use the same commands you did for the first one, except start with a .find for the second iframe.

spec.js

it('test', () => {
  cy.visit('index.html')
  cy.get("#iframe")
    .its('0.contentDocument.body').should('not.be.empty')
    .then(cy.wrap)
    .find('#iframe2')
    .its('0.contentDocument.body').should('not.be.empty')
    .then(cy.wrap)
    .contains('IFRAME 2')
})

index.html

<html>
<body>
  <iframe id="iframe" src="iframe.html"></iframe>
</body>
</html>

iframe.html

<html>
<body>
  IFRAME 1
  <iframe id="iframe2" src="iframe2.html"></iframe>
</body>
</html>

iframe2.html

<html>
<body>
  IFRAME 2
</body>
</html>

Screen Shot 2021-03-01 at 12 43 14 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants