Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cypress: Get all elements that have some specific attribute equal to any value

I am trying to get all elements that just have a specific attribute, doesn’t matter what the attribute value is, and count the number of elements found.

for example get all attribute that has "row-index" attribute:

<div row-index="0" style="height: 47px; transform: translateY(0px);">aaa</div>
<div row-index="1" style="height: 47px; transform: translateY(0px);">bbb</div>
<div row-index="3" style="height: 47px; transform: translateY(0px);">ccc</div>

I have tried this code, that doesn’t work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cy.get('div[@row-index]').should('have.length', 3);

>Solution :

You can also directly use row-index for this:

cy.get('[row-index]').should('have.length', 3);

Another way to assert length:

cy.get('[row-index]').its('length').should('eq', 3);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading