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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Do not call .type(''). Cypress rejects an empty string with CypressError: cy.type() cannot accept an empty String. You need to actually type something. Use .clear() when the test must make a field empty, or skip .type() when optional data is blank. If you are testing a required field, leave it blank and perform the interaction that causes validation instead of pretending that the user typed “nothing.”

The behavior is intentional: .type() models text entry, and there is no text-entry event for an empty string. Cypress issue #6157 requested that an empty string become a no-op; the issue is closed with a wontfix label, so do not rely on cy.type('') becoming supported. See the Cypress .type() API reference and issue #6157.

Choose the command that matches the user action

Test intent Use What to assert
Set an existing value to empty cy.get(selector).clear() The input value is empty and the application responds to clearing
Enter optional data that may be blank Call .type(value) only when value !== '' The field contains the supplied value when one exists
Represent a user who never entered anything Do not type; focus, blur, submit, or otherwise perform the relevant interaction Required-field validation, untouched state, or submit behavior
Enter whitespace deliberately Pass a non-empty whitespace string, such as ' ', only when that is the behavior under test Your application’s trimming and validation rules

These choices are not interchangeable. Clearing a field changes its value and can fire the input-related behavior your application attaches to deletion. Leaving it untouched preserves the distinction between “the user did not edit this field” and “the user edited it and removed the value.”

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

Clear an input when the required state is empty

Select the control and use .clear(). Cypress documents .clear() as the related command for removing text from an input or textarea.

#1 Best Overall
Amazon Basics Wired QWERTY Keyboard, Works with Windows, Plug and Play, Easy to Use with Media Control, Full-Sized, Black
  • KEYBOARD: The keyboard works for Windows with hot keys that enable easy access to Media, My Computer, Mute, Volume up/down, and Calculator
  • EASY SETUP: Experience simple installation with the USB wired connection
  • VERSATILE COMPATIBILITY: This keyboard is designed to work with multiple Windows versions, including Vista, 7, 8, 10 offering broad compatibility across devices.
  • SLEEK DESIGN: The elegant black color of the wired keyboard complements your tech and decor, adding a stylish and cohesive look to any setup without sacrificing function.
  • FULL-SIZED CONVENIENCE: The standard QWERTY layout of this keyboard set offers a familiar typing experience, ideal for both professional tasks and personal use.
cy.get('[data-cy="name"]').clear()
cy.get('[data-cy="name"]').should('have.value', '')

If your component validates on blur, include that interaction explicitly:

cy.get('[data-cy="name"]').clear().blur()
cy.get('[data-cy="name-error"]')
  .should('be.visible')
  .and('contain', 'Name is required')

Use the assertion your application actually promises. A browser’s native constraint validation, a framework-level error message, and a server-side response are different outcomes; Cypress does not invent a validation rule for you.

Skip `.type()` for optional values

Data-driven tests often receive an empty string. Branch before invoking 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.
const value = ''
const name = cy.get('[data-cy="name"]')

if (value !== '') {
  name.type(value)
}

For a reusable helper, keep the empty-value policy visible rather than hiding it in a command that silently changes test meaning:

function typeWhenPresent(selector, value) {
  cy.get(selector).then(($input) => {
    if (value !== '') {
      cy.wrap($input).type(value)
    }
  })
}

typeWhenPresent('[data-cy="nickname"]', optionalNickname)

If the test setup requires a known empty state, clear first and then conditionally type. This avoids leaking a value from a previous test or from a field prefilled by the application:

cy.get('[data-cy="nickname"]').clear()

if (optionalNickname !== '') {
  cy.get('[data-cy="nickname"]').type(optionalNickname)
}

Use a strict comparison with '' when the contract is specifically a string. Do not automatically treat null, undefined, 0, or false as empty text unless that conversion is part of your application’s data model. Normalize those values deliberately before the Cypress command.

Rank #2
Sale
Logitech MK270 Full Size Wireless Keyboard and Mouse Combo - Black
  • Reliable Plug and Play: The USB receiver provides a reliable wireless connection up to 33 ft (1), so you can forget about drop-outs and delays and you can take it wherever you use your computer
  • Type in Comfort: The design of this keyboard creates a comfortable typing experience thanks to the low-profile, quiet keys and standard layout with full-size F-keys, number pad, and arrow keys
  • Durable and Resilient: This full-size wireless keyboard features a spill-resistant design (2), durable keys and sturdy tilt legs with adjustable height
  • Long Battery Life: MK270 combo features a 36-month keyboard and 12-month mouse battery life (3), along with on/off switches allowing you to go months without the hassle of changing batteries
  • Easy to Use: This wireless keyboard and mouse combo features 8 multimedia hotkeys for instant access to the Internet, email, play/pause, and volume so you can easily check out your favorite sites

Test a blank required field without typing

To model a user who submits no value, start with an empty control and drive the event that your product uses to validate it. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.get('[data-cy="email"]').should('have.value', '')
cy.get('[data-cy="email"]').focus().blur()
cy.get('[data-cy="email-error"]')
  .should('be.visible')
  .and('contain', 'Email is required')

For submit-time validation:

cy.get('[data-cy="signup-form"]').submit()
cy.get('[data-cy="email-error"]')
  .should('contain', 'Email is required')

If the field starts with a fixture value, clear it as setup, then submit or blur. If “untouched” is itself a product state, do not clear it; assert the untouched state and perform only the interaction needed to reach the expected result.

Understand the empty string error

The maintained Cypress issue records the exact failure:

CypressError: cy.type() cannot accept an empty String. You need to actually type something.

This is different from an assertion failure. Cypress stops before typing, so adding retries, a longer timeout, or a forced action does not turn an empty string into a valid command. The fix is to change the command or the test data branch.

The current API reference describes .type(text) as typing a string into a DOM element. It also notes that Cypress 16.0.0 changed the default typing delay from 10 ms to 0 ms; that timing change does not alter the empty-string rule. If your test depends on per-character timing, configure the documented delay for a non-empty value rather than using an empty call.

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

.type(), .clear(), and .press()

.type() is for text and supported sequences

Use it when there is actual text or a supported special sequence to enter:

Rank #3
Sale
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
  • All-day Comfort: The design of this standard keyboard creates a comfortable typing experience thanks to the deep-profile keys and full-size standard layout with F-keys and number pad
  • Easy to Set-up and Use: Set-up couldn't be easier, you simply plug in this corded keyboard via USB on your desktop or laptop and start using right away without any software installation
  • Compatibility: This full-size keyboard is compatible with Windows 7, 8, 10 or later, plus it's a reliable and durable partner for your desk at home, or at work
  • Spill-proof: This durable keyboard features a spill-resistant design (1), anti-fade keys and sturdy tilt legs with adjustable height, meaning this keyboard is built to last
  • Plastic parts in K120 include 51% certified post-consumer recycled plastic*
cy.get('[data-cy="search"]').type('cypress')

.clear() expresses deletion

Use it when the expected user action is removing the current value:

cy.get('[data-cy="search"]').clear()

.press() expresses a key press

Cypress documents cy.press() for navigation and single-key events. Use it when the behavior depends on a real key, such as moving focus or triggering an Enter action, not as a substitute for clearing a field:

cy.get('[data-cy="search"]').focus()
cy.press('Tab')
cy.get('[data-cy="results"]')
  .should('be.visible')

A space is not an empty string. .type(' ') requests one whitespace character and should be tested only when whitespace handling is the requirement.

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

Common failures and fixes

The value comes from a fixture and is sometimes empty

Symptom: the test fails only for certain rows with the empty-string CypressError.

Fix: clear as setup if needed, then guard the type call:

cy.get('[data-cy="title"]').clear()
if (row.title !== '') {
  cy.get('[data-cy="title"]').type(row.title)
}

You used a truthy check and changed the data contract

Symptom: values such as 0 or false disappear unexpectedly.

Rank #4
Redragon K521 Upgrade Rainbow LED Gaming Keyboard, 104 Keys Wired Mechanical Feeling Keyboard with Multimedia Keys, One-Touch Backlit, Anti-Ghosting, Compatible with PC, Mac, PS4/5, Xbox
  • 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
  • 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
  • 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
  • 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
  • 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use

Fix: normalize explicitly and compare the resulting string with ''. A truthy check is appropriate only when every falsy value is intentionally equivalent to “no text.”

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

You expected an untouched field but called .clear()

Symptom: dirty-state or touched-state assertions fail.

Fix: remove the clear action. Assert the initial value, then focus, blur, submit, or press the key that your UI uses to expose the behavior.

You tried { force: true }

Symptom: the command still rejects the value.

Fix: force controls actionability checks; it does not supply text. Branch around the call or use .clear().

You are debugging a secret value

Cypress records .type() content in the Command Log by default. Follow the Cypress guidance for logging and masking sensitive values when typing passwords, tokens, or other secrets. This concern is separate from empty-string handling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reliable patterns for data-driven suites

Table-driven cases

Make the intended state explicit in each case:

const cases = [
  { label: 'empty', value: '', expectedError: true },
  { label: 'present', value: 'Ada', expectedError: false }
]

cases.forEach(({ label, value, expectedError }) => {
  it(`handles ${label} name`, () => {
    cy.get('[data-cy="name"]').clear()
    if (value !== '') {
      cy.get('[data-cy="name"]').type(value)
    }
    cy.get('[data-cy="name"]').blur()
    cy.get('[data-cy="name-error"]')
      .should(expectedError ? 'be.visible' : 'not.exist')
  })
})

Custom commands

If your team adds a helper, document whether it means “leave untouched,” “make empty,” or “type when present.” Ambiguous helpers make validation tests difficult to review. Keep the underlying Cypress command recognizable so failures point to the actual user action.

Best Value
Sale
Logitech K270 Full Size Wireless Keyboard for Windows - Black
  • All-day Comfort: This USB keyboard creates a comfortable and familiar typing experience thanks to the deep-profile keys and standard full-size layout with all F-keys, number pad and arrow keys
  • Built to Last: The spill-proof (2) design and durable print characters keep you on track for years to come despite any on-the-job mishaps; it’s a reliable partner for your desk at home, or at work
  • Long-lasting Battery Life: A 24-month battery life (4) means you can go for 2 years without the hassle of changing batteries of your wireless full-size keyboard
  • Simply plug the USB receiver into a USB port on your desktop, laptop or netbook computer and start using the keyboard right away without any software installation
  • Simply Wireless: Forget about drop-outs and delays thanks to a strong, reliable wireless connection with up to 33 ft range (5); K270 is compatible with Windows 7, 8, 10 or later

Or skip the browser setup

If you need a clean screenshot of a page or test fixture rather than a browser script, ScreenshotNeo provides a single HTTP call. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server also lets Claude, Cursor, or another MCP client call take_screenshot, get_page_info, and capture_pdf.

Here is a direct request (replace the URL and key):

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 API documentation for all parameters, including viewport and device settings, element selectors, wait conditions, custom CSS or JavaScript, request blocking, cookies, headers, geolocation, PDF output, caching, signed links, asynchronous jobs, bulk capture, and usage reporting.

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

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account to try it.

Practical checklist

  • Use .clear() to set a field’s current value to empty.
  • Guard optional data and call .type() only for a non-empty string.
  • For required-field tests, leave the field blank and trigger the real validation interaction.
  • Use .press() for navigation or a single key; it does not clear an input.
  • Treat whitespace, null, numbers, and booleans according to an explicit data contract.
  • Do not expect force, retries, or delays to make .type('') valid.

Frequently Asked Questions

Can I conditionally call `.type()` in a Cypress chain?

Yes. Resolve the value, then branch in JavaScript and invoke `.type(value)` only when the value is not the empty string. Use a separate Cypress command for the non-empty branch so the test remains readable.

How do I verify that clearing actually changed the control?

Chain an assertion such as `.should(‘have.value’, ”)`, then perform the blur, submit, or other interaction that your application uses to validate the cleared state.

Does a string containing one space count as empty to Cypress?

No. A space is a non-empty string and can be passed to `.type()`. Whether your application trims or rejects it is an application rule that you should assert separately.

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

Quick Recap

Bestseller No. 1
SaleBestseller No. 3
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Logitech K120 Full Size Wired Keyboard USB Plug-and-Play Windows - Black
Plastic parts in K120 include 51% certified post-consumer recycled plastic*; Product carbon footprint: 4.02 kg CO2e
$12.34
SaleBestseller No. 5
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Logitech K270 Full Size Wireless Keyboard for Windows - Black
Plastic parts in K270 include 38% certified post-consumer recycled plastic; Eight hot keys: For instant access to the Internet, e-mail, music volume and more
$23.99

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.