I have a card with more information that has the next html code. I want each card, except for the first one (so somehow to increase from 1 with the start), to press the "Edit location" button, then to write in the code and other actions for it, and then to move to the next card.
How can I write this in Cypress?
I used this code in Cypress, but no loop is executed, it runs only once on the first card and then stops.
cy.get(".card-locations").each(($el, index) => {
if (index > 0) {
cy.wrap($el).contains("Edit location").click({ force: true });
//another code
}
});
HTML code:
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 card no-select card-locations">
<!-- card header -->
<div class="card-top-gradient card-top-gradient-noactions animated fadeInDown card-top-gradient-default">
<!-- card content -->
<div class="card-content">
<div class="card-right-content">
<div class="card-name">
Location Craiova
</div>
<div class="card-clinic-name">
Bucharest <br>
-- 020202 Romania
</div>
<ul class="card-details card-details-verbose">
<li>
<span class="field-name">Timezone</span>
<span class="field-value">(UTC+02:00) Athens, Bucharest</span>
</li>
<li>
<span class="field-name">Facility code</span>
<span class="field-value">11 Office</span>
</li>
<li>
<span class="field-name">Phone number</span>
<span class="field-value"></span>
</li>
<li>
<span class="field-name">Email address</span>
<span class="field-value"><a href="mailto:[email protected]">[email protected]</a></span>
</li>
</ul>
</div>
</div>
</div>
<!-- card footer -->
<div class="card-footer" style="background-color: #186b65;">
<div class="button-placeholder">
<div class="card-button card-properties footer-left-button">
<span data-action="edit" class="edit" entity-detail="editEntity" title="Edit Location" onclick="$.cmtBhv().getJson({ url: '/...' }).toggleEntityDetailsFor({ target: this });">Edit location</span>
</div>
<div class="card-button card-properties footer-right-button">
<span data-action="edit" class="edit" entity-detail="editEntity" onclick="$.cmtBhv().getJson({ url: '/...' }).toggleEntityDetailsFor({ target: this });">Rooms</span>
</div>
</div>
</div>
</div>