skip to Main Content

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


  1. 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

    myPage.go()
      .side_Bar()
      .should('contains', 'expected text')
    
    Login or Signup to reply.
  2. 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

    <div>expected text</div>
    

    and I run your test

    cy.get('div')
      .should('contains', 'expected text')
    

    I get the same error:

    Timed out retrying after 4000ms: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given

    but switching to the text content, the test passes

    cy.get('div')
      .invoke('text')
      .should('contains', 'expected text')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search