I am facing an issue in Cypress. The CSS locator I am using seems to be correct I can find it when searching it directly in my page. However Cypress is throwing this error
AssertionError Timed out retrying after 30000ms: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given
Here is my locator :
#verification_center_page_exposure > div:nth-child(4) > div:nth-child(2) > div:nth-child(2)> div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(3) > div:nth-child(2) > div:nth-child(2)
I know that for a table or a list we need to loop through elements but this is a simple nested div I don’t know why Cypress is not able to check this code :side_Bar is referring to the correct locator I have already share above.
const myPage = new myPage(ele)
myPage.go()
cy.get("#verification_center_page_exposure > div:nth-child(4) > div:nth-child(2) > div:nth-child(2)> div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(3) > div:nth-child(2) > div:nth-child(2)")
.should('contains', 'expected text')
2
Answers
It’s just a typo, you forgot to put some brackets on the method call, that is why that particular error occurs (but not very informative).
Do this way
You will need to change the subject from the jQuery object yielded by
cy.get(...)
to the text within that element.If I use this simple HTML
and I run your test
I get the same error:
but switching to the text content, the test passes