I am writing an automation test that checks user's ability to schedule an appointment via the calendar. Some dates on the calendar are disabled (aria-disabled="true" ), some are enabled and available for selection (aria-disabled="false"). Depending on when the test is running, the disabled/enabled status of each date is going to change. How do I use Cypress to select the first date button that is not disabled?
Here's what the button's HTML look like, just in case:
<button class="calendar-date" aria-label="Thursday July 28th, 2022"
aria-pressed="false" aria-disabled="false" tabindex="-1"
type="button" data-datestring="ThuJul282022">
28
</button>
You can filter the buttons
cy.get('button.calendar-date')
.filter('[aria-disabled="false"]') // buttons not disabled
.eq(0) // first one
.click()
cy.get('button.calendar-date[aria-disabled="false"]') // buttons not disabled
.eq(0) // first one
.click()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With