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 issueCurrent 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:
- Created 2 years ago
- Comments:11 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
CypressError cy.type() failed because it requires a DOM element.
The subject received was:
The previous command that ran was:
On testing stripe test card cy.getWithinIframe(‘[name=“cardnumber”]’).type(‘5454545454545454’);
I’m getting a similar error whilst using the withinIframe command
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