Cypress - for loop

Viewed 33

I have a date picker where I want to click the left arrow till I go to April 2022. First I will open the calendar and then I am using a loop. Here I am going to check whether the selected month is April, if not I am going to continue to click the left arrow. Please tell me whether this is correct.

  myFunction() {
  
for (let i = 1; i <= 11; i += 1) {
  
  cy.get('[style=""] > .CalendarMonth > .CalendarMonth_caption').should('have.text','April 2022')
  cy.get('.DayPickerNavigation_leftButton__horizontalDefault > .DayPickerNavigation_svg__horizontal').click()

}

}

0 Answers
Related