简体   繁体   中英

cypress selecting dates from react-calendar

So I have this annoying issue with the date picker from react-calendar. So the current date is 28th December 2021. I want to select a date in 4 days time. I first have a month comparitor that checks whether the month is next month. In this case it is, so it will use the skip button to select the next month. January is now shown. I now want to select the the 3rd of January, but it would select February instead

在此处输入图像描述 在此处输入图像描述

        cy.get('.react-calendar__month-view__days >')
        .not('[disabled]')
        .each((elem) => {
            if (elem.text() === nextDate.toString()) {
                elem.click();
            }
        });

Using the above code block it goes through each element text (which is date number) and then selects the matching number. But when it comes to having 2 of the same number displayed it fails to select the right date and chooses the following month's date Has anyone come across a similar problem? thanks

Closing this, I should have really saw the CSS. Theres a aria-label="13 January 2022" in the selector, so I can just pass the date I want to select.

cy.get(`[aria-label="${nextDate}"]`).click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM