CodeceptJS – Handling Dropdowns

CodeceptJS – Handling Dropdowns

<<Previous Post               <<Complete CodeceptJS Tutorial>>               Next Post>>


Selects an option in a drop-down select. The field is searched by label | name | CSS | XPath. The option is selected by visible text or by value.

Pre-requisite: Have ‘Visual Studio Code’ IDE installed in your machine (Click here to install if not installed in your machine)

Here is the small Exercise to Handle Dropdowns in Web Pages using CodeceptJS: –

First, I will demonstrate the exercise we need to perform to automate handling dropdowns using CodeceptJS, followed by practically demonstrating the CodeceptJS Automation code for achieving it.


1. Navigate to http://omayo.blogspot.com/

2. Click on the Dropdown menu.

3. Select doc 4 from the Dropdown menu.

Practical Demonstration:

Following are the Steps to Perform the above Exercise (i.e. Handling Dropdowns) using CodeceptJS Automation code in ‘Visual Studio Code’ IDE:

Step 1:- Create a Folder named as CodeceptJS_Handling_Dropdowns(You can create a folder with any name)

Open the Git Bash from the above-created folder (In our case ‘CodeceptJS_Handling_Dropdowns’ folder)

Trigger the below command in Terminal :

npm init -y

The above command will create a default package.json file in the ‘CodeceptJS_Handling_Dropdowns’ folder.

Attached Screenshot for Reference:

Step 2:- Install codeceptjs with webdriverio as a helper. 

Run the below command in Terminal:

npm install codeceptjs webdriverio --save-dev

Step 3:- Generate Configuration File. Since we haven’t created one yet, codeceptJS is smart enough to figure that out and help us through the process.

Run the below command in Terminal:

 npx codeceptjs init

Here are the answers I chose: (Move your arrow buttons on the keyboard to select the options and enter)

  • Where are your tests located ./*_test.js
  • What helpers do you want to use? WebDriver
  • Where should logs, screenshots, and reports to be stored? ./output
  • Do you want localization for tests? (See https://codecept.io/translation/) English (no localization)
  • [WebDriver] Base URL of the site to be tested http://www.omayo.blogspot.com
  • [WebDriver] Browser in which testing will be performed chrome

These were the main points I have selected rest you can go through the screenshot given below:-

Verify codecept.conf.js file gets created successfully

Step 4:- Now Install Selenium standalone service

Run the below command in Terminal:

npm install @wdio/selenium-standalone-service --save-dev

Step 5:- As generated config file doesn’t auto-configure selenium-standalone in its codecept.conf.js file. Open the file in the respective IDE you use, we are using Visual Studio Code as IDE.

wdio: {
    enabled: true,
    services: [“selenium-standalone”]

Step 6:- Write code in the test file. I have written a sample code through which doc 4 value will be selected from the dropdown list(PS: can be done in multiple ways but I am presenting one of the ways). Use this code and paste it into your test file created during the generation of the config file in Step 3

Feature('select value doc 4 from dropdown');
Scenario('User should be able to select drop4 from the dropdown menu', ({ I }) => {
   var dropdownMenu = "#drop1";
   I.selectOption(dropdownMenu,"doc 4");

Step 7:- Run your test file to perform the test.

Run the below command in Visual Studio Code Terminal:

npx codeceptjs run

Download the Project from here (Click here to Download) and Unzip it.

Hopefully, your test completed and passed.
Comment ‘Success’ in this post if you are able to practically achieve this exercise.

Next Steps:

> To learn more about CodeceptJS, continue to the next post (Click on Next Post link below)

> Check complete CodeceptJS Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Ajay Lunia 

Connect to me on LinkedIn (Click here)

On a mission to help the Software Testing Community in all possible ways.

<<Previous Post               <<Complete CodeceptJS Tutorial>>               Next Post>>

Comments (0)

Leave a Reply

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

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp