How to Deselect Dropdown Value in Selenium WebDriver

Deselect dropdown value in Selenium | We know that Selenium WebDriver supports the testing of dropdown elements using a special select class.

Select class in selenium provides various methods to select and deselect dropdown elements.

In this tutorial, we will learn how to deselect dropdown options in selenium when the dropdown option already selected.

Let’s create a test in which we will perform some basic checks, and will then call various methods to select and deselect the options from the dropdown list. So, let us look at a glance complete scenario.

Scenario to Automate:

1. Launch the web browser by creating a WebDriver object.

2. Visit the web page URL (

3. Locate the dropdown element on the web page by By.xpath.

4. Verify that dropdown supports multiple-choice or not.

5. Select multiple options by using methods selectByVisibleText(), selectByValue(), selectByIndex() of select class.

6. Deselect already selected option by using deselectByVisibleText() method of select class.

Let’s create a program to automate the above scenarios. Look at the following source code to understand the concept of deselection.

Program source code:

package seleniumProject; 
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class DeselectOptionExample 
 public static void main(String[] args) 
   WebDriver driver = new FirefoxDriver(); 
   String URL = ""; 

// Wait for some time to load the whole web page. 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

// Locate dropdown element on the web page by By.xpath. 
     WebElement dropdown = driver.findElement(By.xpath("//select[@name='Month']")); 

// Create an object of Select class and pass the dropdown of type WebElement as an argument. 
     Select select = new Select(dropdown); 

// Verify that the dropdown supports multiple-choice or not.. 
      System.out.println("Multiple choices are allowed, Select multiple options in the list "); 
 else { 
    System.out.println("Multiple choices are not allowed"); 
// Select the option "India" by sending visible text. 

// Select an option by sending its value. 

// Select an option by sending its index. 

// Now, we will deselect already selected option by calling deselectByVisibleText() method of the select class. 
   System.out.println("Option May is deselected successfully"); 
       Multiple choices are allowed, Select multiple options in the list 
       Option May is deselected successfully


How to deselect option in dropdown list

As you can see in the above following source code, we have selected three options using three different methods of select class in the dropdown list. Out of three selected options, we deselected one option by using a method deselectByVisibleText() method of select class.

You can also see in the above screenshot, only two selected options are shown after the deselection of one option in the multiple-choice dropdown list.

Hope that this tutorial has covered the important points related to how to deselect dropdown value in Selenium WebDriver. I hope that you will have understood how to deselect the option in the dropdown list and enjoyed the coding.
Thanks for reading!!!
Next ⇒ How to handle Alert in Selenium WebDriver

⇐ PrevNext ⇒

Please share your love