Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get still fails if element doesnt exist #52

Closed
MassimoLobrutto opened this issue Nov 22, 2022 · 2 comments
Closed

Get still fails if element doesnt exist #52

MassimoLobrutto opened this issue Nov 22, 2022 · 2 comments
Labels
question Further information is requested

Comments

@MassimoLobrutto
Copy link

I have 3 elements that appear depending on the test that use the locators

"app-target-taxonomies-toolbar span:nth-child(1) span"
"app-target-taxonomies-toolbar span:nth-child(2) span"
"app-target-taxonomies-toolbar span:nth-child(3) span"

i used the below code with your library so that if visible it grabs the text in these elements and wraps them in a variable

        cy.get(app-target-taxonomies-toolbar span:nth-child(1) span").if('visible').invoke('text').then(tagTextDisplayed => {
            cy.wrap(tagTextDisplayed.trim()).as('tagTextDisplayed1').else().log("No tag present")
        })
        cy.get(app-target-taxonomies-toolbar span:nth-child(2) span").if('visible').invoke('text').then(tagTextDisplayed => {
            cy.wrap(tagTextDisplayed.trim()).as('tagTextDisplayed2').else().log("No tag present")
        })
        cy.get(app-target-taxonomies-toolbar span:nth-child(3) span").if('visible').invoke('text').then(tagTextDisplayed => {
            cy.wrap(tagTextDisplayed.trim()).as('tagTextDisplayed3').else().log("No tag present")
        })

In my test only 2 of the 3 tags are displayed

Expected Results : Find the 2 present tags and wrap the variable , the 1 missing tag is logged as as "No tag present"
Actual Result: Finds the 2 present tags but chokes on the missing tag.

image

@bahmutov
Copy link
Owner

I think your element does not exist, but you use the assertion if('visible'). Check out my example at 431defa I hope it helps

@bahmutov bahmutov added the question Further information is requested label Nov 22, 2022
@MassimoLobrutto
Copy link
Author

Looks like a compatibility issue, updated to your latest (that has v11 compatibility changes) and it works as expected even with 'visible' :) you can close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants