failed because it requires a DOM element, window or document. #28836
Unanswered
srclay
asked this question in
Questions and Help
Replies: 1 comment
-
Found the problem and it's been logged for like 4 years now - #2831 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an after hook that looks like this:-
cy.visit(Cypress.env('portal_url'))
cy.get('div').eq(0).then(($root) => {
if($root.find('[name=email]').length !== 0) {
....
when running a test, the cy.get('div') line fails with "cy.then() failed because it requires a DOM element, window or document." even though there is definitely at least one div element on the page. Originally I tried with
cy.root().then(($root) => {
with the same results and then I tried with
cy.document().then(($root) => {
also with the same results.
It appears as though Cypress thinks there are no elements on my page. Has anyone else ever seen something similar?
The reason for the code is to check whether the user is already logged in (in which case $root.find('[name=email]').length will equal 0. And the reason for this, is that the user is logged in during a before hook and some test environments keep the user logged in (retaining cookies) while other test environments don't.
Beta Was this translation helpful? Give feedback.
All reactions