Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Cypress

How to Handle Date Pickers in Cypress

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The right Cypress approach depends on the control: type a standardized date into a native <input type="date">, but operate a custom calendar through its own controls. In either case, assert the selected value and the application behavior that matters. If the calendar depends on today’s date, freeze the clock so the test is deterministic.

First identify which kind of date picker you have

A native date input is a browser-provided form control. Cypress can type a valid date into it directly. A custom date picker is an application widget—often built from buttons, a grid, or other elements—and must be opened and used according to its own markup and behavior.

Control or goal Cypress approach What to verify
Native <input type="date"> .type('yyyy-MM-dd') The input value and the resulting form or application behavior.
Native date input increment or decrement On Cypress 13.14.0 or later, type {upArrow} or {downArrow}. The resulting value, accounting for the input’s step.
Custom calendar Open it, wait for its date controls to be visible, and select through stable component-specific selectors. The selected date, form value, downstream results, and expected close behavior.
Date range picker Select the start and end dates separately using the component’s interaction pattern. Both endpoints and the completed range state.
Calendar whose state depends on today Freeze the Date clock before opening it. The expected initial month, enabled dates, and selection behavior.

Type a date into a native input

Cypress documents that .type() on a date input requires a valid date in yyyy-MM-dd format. For example:

cy.get('input[type="date"]')
  .type('2026-09-29')
  .should('have.value', '2026-09-29')

The input’s value uses the standardized date representation, even though the browser may display it differently depending on the browser and locale. Write the test against the value rather than assuming the visible control shows the same sequence of characters. See the Cypress cy.type() documentation.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a selector that identifies the intended field in your application. If the page has several date inputs, prefer a stable test attribute or a label-based query over a broad selector that could target the wrong field. Then assert the value and, where relevant, submit the form and verify the behavior the date is meant to control.

cy.get('[data-cy="departure-date"]')
  .type('2026-09-29')
  .should('have.value', '2026-09-29')

cy.get('[data-cy="search-form"]').submit()
cy.get('[data-cy="search-results"]')
  .should('be.visible')

The final assertion should match the user-facing requirement: for example, that results use the chosen date, an error appears for an invalid range, or a confirmation reflects the submitted date. A value assertion alone does not prove that the application handles the date correctly.

Increment or decrement with arrow keys

Cypress documents {upArrow} and {downArrow} support for date-like inputs beginning with Cypress 13.14.0. On date inputs, the increment or decrement follows the control’s step setting. Check your Cypress version and the field’s attributes before relying on a particular change.

cy.get('input[type="date"]')
  .type('2026-09-29')
  .type('{upArrow}')
  .should('not.have.value', '2026-09-29')

That assertion confirms a change but not its exact amount. If the expected step is part of the requirement, assert the precise resulting value for the input configuration under test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test a custom calendar through its controls

A custom calendar does not become a native date input just because it looks like one. Its DOM structure and accessible labels depend on the component, so inspect the application and choose selectors for the actual controls: the opener, month navigation, and the intended day. Cypress’s cy.select() documentation describes selecting an option within a <select>; it is not the general way to select a date from a calendar grid made of buttons or other elements.

A typical custom-picker test follows this sequence:

  1. Open the date picker using the same control a user would use.
  2. Assert that the calendar or its header is visible before interacting with dates.
  3. Navigate to the required month if needed.
  4. Select the intended day using a stable selector, such as an accessible name or a component-provided date attribute.
  5. Assert that the field or selected-date display contains the expected date.
  6. Assert the relevant application result and any expected calendar close behavior.

For example, if the component exposes a data-date attribute in ISO format, the interaction might look like this:

cy.get('[data-cy="date-picker-trigger"]').click()
cy.get('[data-cy="calendar-header"]').should('be.visible')
cy.get('[data-date="2026-09-29"]').click()
cy.get('[data-cy="selected-date"]')
  .should('contain', '2026-09-29')
cy.get('[data-cy="calendar-header"]').should('not.exist')

This is an example pattern, not universal calendar markup. A component may use a different date attribute, accessible label, or close behavior. The Cypress-maintained real-world custom-command example demonstrates a range picker with a calendar header and data-date selectors; adopt its idea of expressing the target date clearly, not its component-specific selectors as if all calendars shared them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prefer observable state to arbitrary delays

Wait for the UI state you need, rather than inserting a fixed sleep and hoping the calendar has opened. Cypress retries assertions, and its commands apply actionability checks. Asserting visibility before a click helps distinguish a slow or unopened widget from a selector that does not match. The Cypress introduction explains retryability, and its interaction guidance describes how Cypress determines whether an element can be acted on.

cy.get('[data-cy="date-picker-trigger"]').click()
cy.get('[data-cy="calendar-header"]').should('be.visible')
cy.get('[data-date="2026-09-29"]').should('be.visible').click()

If the date is outside the currently displayed month, use the widget’s navigation controls and assert the month header changes before selecting it. Do not assume a day number is unique: a calendar may show adjacent-month dates in the same grid, and the same number occurs in every month.

Make date-range tests deterministic

A calendar may open to the current month, disable dates relative to today, or initialize one range endpoint based on the current date. A test that uses the real clock can change behavior when it runs on another day. Cypress’s maintained example controls the Date clock before opening the picker:

const startDate = new Date('2026-09-29T12:00:00Z')
cy.clock(startDate.getTime(), ['Date'])

cy.get('[data-cy="range-picker-trigger"]').click()
cy.get('[data-cy="calendar-header"]').should('be.visible')
cy.get('[data-date="2026-09-29"]').click()
cy.get('[data-date="2026-10-05"]').click()

cy.get('[data-cy="range-picker-header"]').should('not.exist')
cy.get('[data-cy="range-start"]').should('have.value', '2026-09-29')
cy.get('[data-cy="range-end"]').should('have.value', '2026-10-05')

Adapt the selectors and close-state assertion to your widget. The example’s important design choices are to fix the calendar’s date context, wait for the calendar header, identify dates by a full date attribute, select each endpoint, and verify the completed state. If a reusable range interaction appears across tests, wrap your application-specific steps in a custom Cypress command; keep the assertions that express each test’s distinct requirement near that test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Freezing Date is appropriate when the behavior under test depends on the current date. Avoid freezing unrelated time APIs unless the application’s behavior requires it, and set the clock before the UI reads the current date.

Choose the test boundary deliberately

Typing into a native field verifies form input behavior; clicking through a custom calendar verifies the widget interaction. A test that only needs to check submitted date handling may not need to exercise every calendar navigation control. Conversely, if the requirement is that users can open the widget, move months, and choose a day, setting a value directly bypasses the behavior that matters.

Directly assigning a value and triggering an event is another boundary: it does not reproduce all the steps of a user interaction. Cypress’s cy.trigger() documentation notes that direct event triggering can be problematic in some situations. Select an approach that matches the requirement, and assert the resulting application state rather than treating an event firing as proof of success.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

The native input rejects the date

  • Cause: The string is not a valid date in the required yyyy-MM-dd form.
  • Fix: Use a zero-padded month and day, such as 2026-09-29, and assert the input value after typing.

The date looks different in the browser

  • Cause: Native input display is browser- and locale-dependent, even though its value follows the standardized format.
  • Fix: Assert the standardized input value or application output, not a presumed visual date order.

cy.select() cannot choose a calendar day

  • Cause: The calendar is rendered from buttons, grid cells, or other custom elements rather than a <select>.
  • Fix: Open the widget and interact with its actual date controls using selectors specific to that component.

The day selector matches the wrong date or more than one element

  • Cause: A day number alone is ambiguous, or adjacent-month dates are rendered in the same grid.
  • Fix: Select by a full date attribute or an accessible name that identifies the full date, and scope the query to the active calendar when appropriate.

The click fails because the date is not actionable

  • Cause: The calendar may not be open yet, the target may be hidden or disabled, or another element may cover it.
  • Fix: Assert the calendar is visible, verify the intended date control is visible and enabled, and address the UI state that prevents interaction. Do not default to forced clicks; they can conceal a real usability or state problem.

The test changes behavior from day to day

  • Cause: The initial month or enabled-date rules depend on the real current date.
  • Fix: Set the Date clock before opening the picker and assert the expected month and selection behavior.

An arrow-key test behaves differently than expected

  • Cause: The project may run a Cypress version earlier than 13.14.0, or the input’s step changes the increment.
  • Fix: Confirm the installed Cypress version and inspect the input’s step configuration before asserting a specific result.

Or skip the browser setup

If what you need is a screenshot of a page containing a date picker—not an end-to-end test of its interaction—ScreenshotNeo can capture the page through one GET request. Keep Cypress for verifying the picker behavior; a screenshot call captures a rendered page and does not replace those interaction assertions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for 1,000 free screenshots a month—no card required.

Frequently Asked Questions

Does Cypress use the same date format that the browser displays?

Not necessarily. The native input value follows the standardized yyyy-MM-dd format, while its visible display can vary by browser and locale.

Can I use cy.select() on a calendar day?

Only if the date control is genuinely an option inside a select element. Most custom calendars require interacting with their own controls.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use this pattern with any date picker library?

The interaction pattern is general, but selectors and state transitions are component-specific. Inspect your widget’s markup and accessible controls.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.