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.

cy.type() failed because it requires a DOM element. The subject received was: <window> The previous command that ran was: > cy.get()

See original GitHub issue

Current behavior

I use the following custom command:

Cypress.Commands.add('dropdown', {
 prevSubject: ['element', 'document', 'window', 'optional'],   
  }, (subject) => {
    cy.get(subject).type(`{downarrow}{enter}`)
  })

After I run the script in TypeScript format, i get the following error:

type
{downarrow}{enter}
CypressError
cy.type() failed because it requires a DOM element.

The subject received was:

  > <window>

The previous command that ran was:

  > cy.get()

Because this error occurred during a before all hook we are skipping the remaining tests in the current suite: Common PMP workflow

Although you have test retries enabled, we do not retry tests when before all or after all hooks fail

Desired behavior

No errors, everything should work like in a regular JS file, which works just fine

Test code to reproduce

launch the above mentioned command in a file with TS extension

Versions

Cypress version: the latest 7.3.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
IswaryaSekar1510commented, Jun 9, 2022

CypressError cy.type() failed because it requires a DOM element.

The subject received was:

jQuery{0}

The previous command that ran was:

cy.getInDocument()

On testing stripe test card cy.getWithinIframe(‘[name=“cardnumber”]’).type(‘5454545454545454’);

2reactions
boneysajucommented, Aug 3, 2021

I’m getting a similar error whilst using the withinIframe command

cy.type() failed because it requires a DOM element.
The subject received was:
  > jQuery{0}
The previous command that ran was:
  > cy.getInDocument()

The test code is <input class="InputElement is-empty Input Input--empty" autocomplete="cc-number" autocorrect="off" spellcheck="false" type="text" name="cardnumber" data-elements-stable-field-name="cardNumber" inputmode="numeric" aria-label="Credit or debit card number" placeholder="Card number" aria-invalid="false" value="">

^^above solved by adding a wait

Read more comments on GitHub >

github_iconTop Results From Across the Web

cy.click() failed because it requires a DOM element?
I have logout function in afterEach hook. But at the time of 3rd test case, it is showing me an error of "cy....
Read more >
cy.click() failed because it requires a dom element. - You.com
The previous command that ran was: > cy. debug() This DOM element likely became detached somewhere between the previous and current command.
Read more >
Error Messages | Cypress Documentation
Getting this error means you've tried to interact with a "dead" DOM element - meaning the current subject has been removed from the...
Read more >
cypress-io/cypress - Gitter
CypressError: cy.type() failed because it requires a DOM element. The subject received was: > Object{9} The previous command that ran was: > cy.wait()....
Read more >
Solving The Element Is Detached From DOM Error In Cypress
wait(xxx) command to wait for a second or two. I mean, if it fixes the detached element problem and the test becomes stable,...
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