Cypress: Unable to get element count using Cypress.$

Created on 29 Apr 2020  路  1Comment  路  Source: cypress-io/cypress

I am trying to get the element count using below method :

cy.log(Cypress.$('tr.dx-row-lines').length)

but it always print 0

while If I use code like below :
 cy.get("body").then(($el) =>{
    cy.log ($el.find("tr.dx-row-lines").length) 
}

it print 4

Because I need to break a for loop if rows found so I can not use 2nd way,

Please guide me

question

>All comments

Cypress.$('tr.dx-row-lines').length is evaluated immediately because it is a sync method. so it's evaluating before other Cypress code is ran.

I suggest reading the entirety of our Introduction to Cypress guide. Specifically the section on mixing async and sync code.

Issues in our GitHub repo are reserved for potential bugs or feature requests. This issue will be closed since it appears to be neither a bug nor a feature request.

We recommend questions relating to how to use Cypress be asked in our community chat. Also try searching our existing GitHub issues, reading through our documentation, or searching Stack Overflow for relevant answers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Francismb picture Francismb  路  3Comments

brian-mann picture brian-mann  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

tahayk picture tahayk  路  3Comments