简体   繁体   English

柏树从反应日历中选择日期

[英]cypress selecting dates from react-calendar

So I have this annoying issue with the date picker from react-calendar.所以我对 react-calendar 的日期选择器有这个烦人的问题。 So the current date is 28th December 2021. I want to select a date in 4 days time.所以当前日期是 2021 年 12 月 28 日。我想 select 在 4 天内的日期。 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.在这种情况下,它会在下个月使用跳转按钮到 select。 January is now shown.现在显示一月。 I now want to select the the 3rd of January, but it would select February instead我现在想在 1 月 3 日 select,但它会在 2 月改为 select

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

        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?但是,当显示 2 个相同的数字时,它无法 select 正确的日期并选择下个月的日期有没有人遇到过类似的问题? thanks谢谢

Closing this, I should have really saw the CSS.关闭这个,我应该真的看到了 CSS。 Theres a aria-label="13 January 2022" in the selector, so I can just pass the date I want to select.选择器中有一个aria-label="13 January 2022" ,所以我可以将我想要的日期传递给 select。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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