cypress: Failed to find body in content Document
Current behavior
its .0.contentDocument.body - assert expected <body> not to be empty
Desired behavior
correctly find the body on the webpage
Test code to reproduce
its occurring in the beforeEach not relation to any individual test
Cypress Version
10.8.0
Node version
v16.16
Operating System
MacOS current
Debug Logs
Timed out retrying after 6000ms: cy.its() errored because the property: contentDocument returned a null value. The property: body does not exist on a null value.
cy.its() waited for the specified property body to become accessible, but it never did.
If you do not expect the property body to exist, then add an assertion such as:
cy.wrap({ foo: null }).its('foo.baz').should('not.exist')
Because this error occurred during a before each hook we are skipping the remaining tests in the current suite:
Other
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
Hiya guys, did some digging and this was the solution that I found.
chromeWebSecurity(set to false)Notice how I’ve used
contentWindowinstead ofcontentDocument. I found it on a tutorial here. An oldie but a goodie.Essentially, imagine you were in the javascript console in your browser and you were searching for an element inside an iframe there. Whatever is returned I wrap up and send back to cypress for more chaining and testing code.
NOTE. Make sure the iframe is fully loaded before calling this. Lest the content of the iframe will return null and make your tests flaky. I personally used
cy.interceptandcy.waitto check when certain network requests were complete and then run my iframe automation testing codeIs the iframe feature now available? I am facing a similar issue and the iframe is from a different origin
@mud1387 please open a new issue with your example and details on how to reproduce what you are seeing. We will be happy to take a look and see if we can help.