question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Cannot read property 'body' of null` error when using `.type()` in a contenteditable body element inside an iframe

See original GitHub issue

Current behavior:

When trying to type inside of an iframe where the target element is either the body element with contenteditable=true or a child of the body, then an exception is throw from Cypress and the command fails. This worked successfully in 3.4.1, but is now failing in 3.7.0.

We use the Froala wysiwyg editor library v2.9 which creates the editor as an iframe with the body element set with contenteditable=true. So we can no longer run e2e tests which type text into the editor with Cypress 3.7.0.

Desired behavior:

Cypress successfully types into the specified element.

Steps to reproduce: (app code and test code)

An example of how to reproduce the error is by running the command,

cy.get('iframe').then(($iframe) => {
  const $body = $iframe.contents().find('body');
  cy.wrap($body).find('p').type('test');
});

With an iframe that contains,

<body contenteditable="true">
 ...
</body>

This produces the following exception.

TypeError: Cannot read property 'body' of null
    at getHostContenteditable (http://localhost:57715/__cypress/runner/cypress_runner.js:107362:29)
    at _getSelectionBoundsFromContentEditable (http://localhost:57715/__cypress/runner/cypress_runner.js:107280:29)
    at Module.getSelectionBounds (http://localhost:57715/__cypress/runner/cypress_runner.js:107602:14)
    at shouldUpdateValue (http://localhost:57715/__cypress/runner/cypress_runner.js:94737:81)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:95442:14
    at Keyboard.performSimulatedDefault (http://localhost:57715/__cypress/runner/cypress_runner.js:95481:11)
    at Keyboard.simulatedKeydown (http://localhost:57715/__cypress/runner/cypress_runner.js:95388:25)
    at Keyboard.typeSimulatedKey (http://localhost:57715/__cypress/runner/cypress_runner.js:95411:12)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:95159:17
From previous event:
    at http://localhost:57715/__cypress/runner/cypress_runner.js:95169:70
From previous event:
    at Keyboard.type (http://localhost:57715/__cypress/runner/cypress_runner.js:95168:62)
    at type (http://localhost:57715/__cypress/runner/cypress_runner.js:87991:23)
    at onReady (http://localhost:57715/__cypress/runner/cypress_runner.js:88133:20)
    at runAllChecks (http://localhost:57715/__cypress/runner/cypress_runner.js:85227:14)
    at retryActionability (http://localhost:57715/__cypress/runner/cypress_runner.js:85235:16)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:85241:7
From previous event:
    at Object.verify (http://localhost:57715/__cypress/runner/cypress_runner.js:85178:21)
    at handleFocused (http://localhost:57715/__cypress/runner/cypress_runner.js:88124:29)
    at Context.type (http://localhost:57715/__cypress/runner/cypress_runner.js:88179:12)
    at Context.<anonymous> (http://localhost:57715/__cypress/runner/cypress_runner.js:100860:21)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:100381:33
From previous event:
    at runCommand (http://localhost:57715/__cypress/runner/cypress_runner.js:100363:14)
    at next (http://localhost:57715/__cypress/runner/cypress_runner.js:100498:14)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:100521:18
From previous event:
    at next (http://localhost:57715/__cypress/runner/cypress_runner.js:100498:34)
From previous event:
    at http://localhost:57715/__cypress/runner/cypress_runner.js:100535:37
From previous event:
    at run (http://localhost:57715/__cypress/runner/cypress_runner.js:100527:15)
    at Object.cy.(anonymous function) [as visit] (http://localhost:57715/__cypress/runner/cypress_runner.js:100894:11)
    at Context.runnable.fn (http://localhost:57715/__cypress/runner/cypress_runner.js:101081:20)
    at callFn (http://localhost:57715/__cypress/runner/cypress_runner.js:30931:21)
    at Test.../driver/node_modules/mocha/lib/runnable.js.Runnable.run (http://localhost:57715/__cypress/runner/cypress_runner.js:30924:7)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:104009:28
From previous event:
    at Object.onRunnableRun (http://localhost:57715/__cypress/runner/cypress_runner.js:103998:17)
    at $Cypress.action (http://localhost:57715/__cypress/runner/cypress_runner.js:97629:30)
    at Test.Runnable.run (http://localhost:57715/__cypress/runner/cypress_runner.js:102935:20)
    at Runner.../driver/node_modules/mocha/lib/runner.js.Runner.runTest (http://localhost:57715/__cypress/runner/cypress_runner.js:31398:10)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:31504:12
    at next (http://localhost:57715/__cypress/runner/cypress_runner.js:31318:14)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:31328:7
    at next (http://localhost:57715/__cypress/runner/cypress_runner.js:31260:14)
    at http://localhost:57715/__cypress/runner/cypress_runner.js:31296:5
    at timeslice (http://localhost:57715/__cypress/runner/cypress_runner.js:26364:27)

Versions

Cypress 3.7.0, 3.6.0, 3.5.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
ghostcommented, Feb 8, 2020

Yes we are heavily affected by this and are stuck on a previous version. We really want to upgrade to 4.0 which has Firefox and Edge support.

5reactions
ghostcommented, Jan 3, 2020

Following this thread as it’s affecting all my cypress tests that have iframes in them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'documentElement ...
javascript - Uncaught TypeError: Cannot read property 'documentElement' of null at Iframe. initializeIframe - Stack Overflow. Stack Overflow ...
Read more >
TypeError: Cannot read property 'setAttribute' of Null in JS
To solve the "Cannot read property 'setAttribute' of null" error, make sure to place the JS script tag at the bottom of the...
Read more >
uncaught typeerror: cannot read properties of null ... - You.com
getElementById will return null if the element is not found in the DOM. null does not have a style property. You can fix...
Read more >
How To Get an Element in an iframe - W3Schools
Click the button to hide the first H1 element in the iframe (another document). Hide H1 Element. Get Element in Iframe. Get the...
Read more >
<input>: The Input (Form Input) element - HTML
The HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found