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

For a native HTML <select>, use Cypress .select() with an option’s value or text, then assert the selected value. Select2 also decorates a backing <select>, but usually hides it behind a custom interface: interact with that visible interface to test the user path, or use .select(value, { force: true }) when deliberately setting up state. In either case, check the value or rendered label your test depends on.

Use Cypress .select() with a native select

Cypress .select() selects an option inside a native <select>. You can pass an option’s value or its displayed text. Assert the actual value attribute afterward, since the label and value can differ.

cy.get('[data-cy="state"]').select('MA')
cy.get('[data-cy="state"]').should('have.value', 'MA')

// You can also select by the option's visible text.
cy.get('[data-cy="state"]').select('Massachusetts')
cy.get('[data-cy="state"]').should('have.value', 'MA')

The selector should identify the intended control rather than all selects on the page. Cypress recommends stable, application-owned data selectors where available; IDs are also suitable when they are stable. See the Cypress selector best practices and select command documentation.

Why .select() can fail on Select2

Select2 replaces a native select’s visible presentation with a custom widget while retaining the original select underneath. The backing element may be hidden, so Cypress’s normal actionability checks can reject .select() even though the element exists. Cypress checks whether an element is actionable before interacting with it; the force option bypasses those checks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

For a test whose purpose is to set and verify the backing state, forcing selection can be appropriate:

cy.get('#favorite-state').select('MA', { force: true })
cy.get('#favorite-state').should('have.value', 'MA')
cy.get('#select2-favorite-state-container')
  .should('have.text', 'Massachusetts')

Check both the underlying value and displayed label if both matter to the test. A forced selection is a shortcut for state setup, not proof that a user can operate the visible widget. Prefer the visible interaction path for end-to-end coverage. Read Cypress’s interaction guidance before using force as a general workaround.

Test the visible Select2 interaction

Open the rendered control, type into its search field when present, select a result, and assert the backing value and rendered selection. The following selectors are illustrative: Select2 markup depends on configuration and version, so inspect your app’s rendered DOM and use stable app-owned selectors where possible.

// Adapt these selectors to the application's Select2 markup.
cy.get('[data-cy="state-select2"]').click()
cy.get('[data-cy="state-select2"] .select2-search__field')
  .type('Massachusetts')
cy.contains('.select2-results__option', 'Massachusetts').click()

cy.get('[data-cy="state"]').should('have.value', 'MA')
cy.get('[data-cy="state-select2"] .select2-selection__rendered')
  .should('contain', 'Massachusetts')

If the page has multiple Select2 controls, scope the search field and results to the intended widget. A broad search-field query may match more than one element, while Cypress’s .type() needs a single target. The IDs and generated Select2 classes in examples are not guaranteed to match your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Handle Select2 multiselects

A Select2 multiselect is backed by a native select with the multiple attribute. For direct state setup, Cypress accepts an array of option values. Verify the selected values; for user-path coverage, interact with the visible widget and check the selected labels or chips as well.

cy.get('#states').select(['MA', 'VT'], { force: true })
cy.get('#states').invoke('val').should('deep.equal', ['MA', 'VT'])

The option values in this example must exist on the backing select. If your test relies on what a user sees, add assertions for the corresponding rendered selections instead of treating the backing array as the only outcome.

Set values programmatically and notify Select2

Select2 listens for change on the select it decorates. When application or test code changes a value programmatically, trigger the event so Select2 and other listeners can observe the update:

$('#mySelect2').val('1').trigger('change')

If you need to notify Select2 without firing unrelated change handlers, its events documentation describes the scoped change.select2 event. Select2 also relays public events through jQuery on the attached select; for example, a select2:select handler can read the selected object at e.params.data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
$('#mySelect2').on('select2:select', (e) => {
  const selected = e.params.data
})

In Cypress, invoking a page’s jQuery or Select2 method can help with state inspection or setup, but does not demonstrate that the rendered control works for a user. Select2 documents its programmatic events and programmatic methods.

Wait for remote Select2 results without fixed sleeps

AJAX-backed Select2 results load asynchronously. Select2 does not create an option node for a remote item until that item has been selected for the first time; afterward, the option remains in the DOM even if selection changes. Do not assume remote results or their option nodes exist before opening and searching the widget.

Open the correct widget, enter a query if needed, then query for the expected result and act on it. Cypress retries queries and assertions while waiting, so a result assertion is generally more robust than an arbitrary fixed delay.

cy.get('[data-cy="city-select2"]').click()
cy.get('[data-cy="city-select2"] .select2-search__field')
  .type('Boston')
cy.contains('.select2-results__option', 'Boston')
  .should('be.visible')
  .click()
cy.get('[data-cy="city"]').should('have.value', 'boston')

Adapt the option value and selectors to the application. For details, see Select2’s AJAX data source documentation and Cypress’s guidance on retry-ability.

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.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Choose the right assertion

Match the assertion to what the test is intended to prove:

  • Backing state: assert the native select’s value, or its array of values for a multiselect.
  • Visible result: assert the rendered label or selected chips after using the visible widget.
  • Application behavior: assert the effect that matters to the app, such as the updated form state or outcome of the selection.

A value assertion alone does not establish that a user could operate a hidden or inaccessible control; a rendered-label assertion alone may not establish the backing value expected by application logic.

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

Troubleshoot common Cypress and Select2 failures

.select() says the element is not visible or actionable

Cause: Select2 commonly hides the original select. Fix: use the visible widget for user-path coverage, or use { force: true } intentionally for backing-state setup and verify the resulting state.

.type() reports multiple elements

Cause: an unscoped search selector matched fields in more than one widget. Fix: scope the query to the specific Select2 container, or use a stable application-owned selector for the intended field.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

The result query finds nothing

Cause: a remote result may not have loaded yet, the widget may not be open, or the typed query may not match. Fix: open and search the right widget, then assert the expected result with a retrying query. Avoid assuming remote options are pre-rendered.

The backing value changes but the displayed widget does not

Cause: code changed the select value without notifying Select2. Fix: trigger change after the programmatic value update, or use the scoped event when appropriate.

A label assertion passes but the expected value does not

Cause: option text and option value are distinct, or the assertion targets only the rendered widget. Fix: inspect the option’s actual value and assert the backing select’s value as well when application logic depends on it.

Or skip the browser setup

If your goal is a website screenshot rather than a Cypress test of Select2 behavior, ScreenshotNeo provides a screenshot API and MCP server. A single GET request can return a screenshot or PDF; see the API documentation.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo can accept cookie or consent banners and remove supported consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include page-verdict and billing headers. Its MCP server gives AI agents screenshot, page-info, and PDF-capture tools. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan.

Frequently Asked Questions

Does Cypress `.select()` work with every custom dropdown?

No. Cypress `.select()` is for options in a native `

Your address stays with us — privacy.