【问题标题】:Pick date in jquery calendar with cypress用柏树在 jquery 日历中选择日期
【发布时间】:2021-03-10 06:27:06
【问题描述】:

我的应用程序中使用了 jquery 日历插件的以下代码 sn-p,并且截断了 cypress 代码以选择日期 1990-10-11

$(function() {
  $("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat:"yy-mm-dd"
  });
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<p>Date: <input type="text" id="datepicker"></p>

    cy.get("#datepicker").click();
    cy.get(".ui-datepicker-month").select("10");
    cy.get(".ui-datepicker-year").select("1990");
    cy.get("table.ui-datepicker-calendar").then(() => {
        cy.contains('11').click();
    });

使用代码我可以更改年份和月份,但无法选择日期。 如何通过 cypress 将日期设置为 1990-10-11

【问题讨论】:

    标签: javascript jquery cypress jquery-ui-datepicker


    【解决方案1】:

    尝试如下点击date11

    cy.get("a.ui-state-default:contains(11)").click();
    

    【讨论】:

      【解决方案2】:

      @Karan 的回答看起来不错,但我会在选择时更加具体(因为 ui-state-default 看起来有点过于笼统)。

      cy.get('[data-handler="selectDay"] a:contains("11")').click()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多