How to Handle Dropdown in Cypress
Related Product On This Page What is Cypress Select?February 06, 2026 · 7 min read · Tool Comparison
Cypressprovides a mere and efficient way to handle dropdowns expend theselect()command, which works in combination withget() and contains (). It allows testers to well interact with dropdown constituent, verify selected values, and control proper functionality across different scenario Different Ways to Select a Dropdown Option in Cypress: This clause exploreshow to handle dropdowns in Cypressfor seamless automation. select() is a command that allows the user to select the dropdown value from the selectedHTML DOM element. Key Features of Cypressselect() Command A dropdown option can be selected using the undermentioned methods: For demonstration, BrowserStack ’ s demo website can be used as a reference. As observed, theOrder by selectdrop-down has three alternative To select the options by index To select the options by value To select the options by text Did you cognize: Here is how to write cypress tests for select dropdown alternative with the three fashion discussed above. In the above code instance, firstly finding the element usingget()and so habituate chain commandselect()to legislate theindex (index begin from 0). In order to ensure that the value take is proper, you can invoke the element ’ s value useinvoke (“ val ”)and assert expendshould() In the above code example, passing the select dropdown option ’ s value to Cypress ’ sselect()function. Note that the prize command acceptsindex, value, and text. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Similar to the above example, here passing the prize dropdown pick ’ s schoolbook to Cypress ’ sselect() function. There are dropdowns that support selecting multiple options; in that causa, you can legislatearray to the select()bidding as seen below There are use cases where you would need to validate if the dip down option selected is the right one and the option is keep in the select drop-down once it ’ s take. You can corroborate this by retrieving the selected value ’ s text like in the below example Read More: You can part discussing with our strife community To run the Cypress test in, follow the below steps 1.Create a folder in your machine, Example,cypress-dropdown-example 2.Open the terminal and navigate to the newly make folder 3. Execute npm initand discharge the installing 4.Install Cypress by executing the below command in the terminal 5.To make a folder structure of cypress, execute the below command in the end 6.Follow the education to make exemplar 7.Inside the Cypress & gt; e2e folder create a new file nominatecypress-dropdown.cy.js 8.Paste the below test code and save the file. 9.Install the BrowserStack Cypress CLI by running the below command in the depot 10.From the root of the repository, fulfill the below bidding to make the BrowserStack conformation file 11.Open the browserstack.json file and update the username and accesskey (This will be available on the BrowserStackAutomate Website for your account) 12.Run the below command in the depot from the root of your secretary to execute the cypress trial in BrowserStack Cloud 13.We can then check the run in Here ’ s why you should run your Cypress tests on Real Devices & amp; Browsers using: This clause demonstrates how to select the dropdown options using Cypress. It also covers using theselect()bid to select the option by its value, index, and textbook. Additionally, you can too validate if the drop-down has selected the value which was think by assertion useshould(). Cypress is a reliable automation tool, but it is important to test the application on a for more accurate test results. By you can identify the bottleneck in the existent user experience and reclaim them in time before liberation. can occupy leverage of powerful cloud platform to run examination in a fast and more efficient way. Understanding Cypress Use Cases Tool Comparisons # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
How to Handle Dropdown in Cypress
Overview
What is Cypress Select?
Different Ways to Select the Dropdown in Cypress
Writing Cypress Tests to Select Dropdown Options
Cypress test for selecting drop-down choice by its index
it.only (`` Validate the dropdown option selection by it 's index '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy.get (`` select '') .select (1) .invoke (`` val '') .should (`` eq '', `` lowestprice '')})Cypress exam for selecting Drop-Down alternative by its value
it.only (`` Validate the dropdown option selection by it 's value '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy.get (`` select '') .select (`` lowestprice '') .invoke (`` val '') .should (`` eq '', `` lowestprice '')})Cypress test for select Dropdown alternative by its text
it.only (`` Validate the dropdown option selection by it 's text '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy.get (`` select '') .select (`` Highest to lowest '') .invoke (`` val '') .should (`` eq '', `` highestprice '')})Selection of multiple options in Dropdown by its text
cy.get (`` select '') .select ([`` option 1 '', `` option 2 ''])
Asserting the select Dropdown options by text is saved
it.only (`` Validate the dropdown option selection by it 's text and assert the selection '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy.get (`` select '') .select (`` Highest to lowest '') cy.get (`` select option: selected '') .invoke (`` textbook '') .should (`` eq '', `` Highest to lowest '')})Like what you are reading?
How to run Cypress Dropdown Tests on Real Devices utilize BrowserStack
npm install cypress -- save-dev
npx cypress open
it (`` Validate the dropdown option option by it 's value '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy .get (`` select '') .select (`` lowestprice '') .invoke (`` val '') .should (`` eq '', `` lowestprice '')}) it (`` Validate the dropdown option selection by it 's value '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy .get (`` take '') .select (`` lowestprice '') .invoke (`` val '') .should (`` eq '', `` lowestprice '')}) it (`` Validate the dropdown alternative choice by it 's text and assert the selection '', () = & gt; {cy.visit (`` https: //www.bstackdemo.com/ '') cy.get (`` select '') .select (`` Highest to lowest '') cy .get (`` choice selection: selected '') .invoke (`` text '') .should (`` eq '', `` Highest to lowest '')})npm install -g browserstack-cypress-cli
browserstack-cypress init
browserstack-cypress run -- sync
Why use BrowserStack Automate for Cypress Tests?
Conclusion
Useful Resources for Cypress
Related Guides
Automate This With SUSA
Test Your App Autonomously