I have a small code snippet that retrieves an array of checkboxes or checkbox labels using cy.get in my Angular application. When looping through the array to click on each element and check the checkboxes, it works fine if the array contains only one element. However, when there are two elements, the second one gets clicked twice, resulting in no checkboxes being selected in the end.
if (formal == Formal.KJOP) {
this.clickOnFinansieringsmuligheterKjop();
}
private clickOnFinansieringsmuligheterKjop(): void {
this.getFinansieringsmuligheterKjop().forEach( (element) => {
element.click({force:true});
});
}
private getFinansieringsmuligheterKjop(): Cypress.Chainable<JQuery<HTMLElement>>[] {
if (Helpers.randomBoolean()) {
return new Array(formalPage.grunnlanTilKjopLabel);
} else {
return new Array(formalPage.grunnlanTilKjopLabel, formalPage.tilskuddUtleieLabel);
}
}
It seems like there might be an issue with how the elements are accessed in the loop, as it works correctly for both clicking on the elements and handling the number of elements.