- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you deselect an option from a static dropdown?
We can deselect an option from a static dropdown with the help of methods under Select class.
The deselect methods are listed below −
deselect_by_value(args) − Deselection with the help of value of option.
This method deselects the option based on the value of the specific option. NoSuchElementException thrown if there is no value which matches with the value given in the argument.
Syntax −
d = Select(driver.find_element_by_id("selection")) d.deselect_by_value('Selenium')
deselect_by_index(args) − Deselection with the help of index of option.
This method deselects the option based on the index of the specific option. The index of the elements mostly start with 0. NoSuchElementException thrown if there is no index which matches with the index given in the argument.
Syntax −
d = Select(driver.find_element_by_id("selection")) d.deselect_by_index(1)
deselect_by_visible_text(args) − Deselection with the help of text displayed of option.
This method is the simplest one which deselects the option based on the visible text. NoSuchElementException thrown if there is no option which matches with the text given in the argument.
Syntax −
d = Select(driver.find_element_by_id("selection")) d.deselect_by_visible_text('Tutorialspoint')
deselect_all() − Deselection of all selected options.
This method is applicable where more than one selection of options can be done. It removes all the options selected from the dropdown. NotImplementedError thrown if it is not possible to select multiple options from the dropdown.
Syntax −
d = Select(driver.find_element_by_id("selection")) d.deselect_all()
Example
Code Implementation for deselection of options in dropdown.
from selenium import webdriver from selenium.webdriver.support.select import Select #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/tutor_connect/index.php") #to refresh the browser driver.refresh() #select class provide the methods to handle the options in dropdown d = Select(driver.find_element_by_xpath("//select[@name='seltype']")) #select an option with visible text method d.select_by_visible_text("By Name") #deselect the option with visible text method d.deselect_by_visible_text("By Name") #select an option with index method d.select_by_index(0) #deselect an option with index method d.deselect_by_index(0) #select an option with value method d.select_by_value("name") #deselect an option with value method d.deselect_by_value("name") #to close the browser driver.close()
- Related Articles
- How to select an option in a static dropdown in Selenium?
- How will you get all the options in a static dropdown?
- How to select a value from a static dropdown in Selenium?
- What are the different ways to select an option from a dropdown using Selenium Webdriver?
- Static Dropdown verification with Cypress
- How to display the selected option in a dropdown list with JavaScript?
- How will you distinguish a colloid from a solution?
- How to deselect a range of rows from a table in Java?
- How will you select a particular value in a dropdown without using the methods of Select class in Selenium?
- How to show the index of the selected option in a dropdown list with JavaScript?
- How to verify if we can select multiple options in a static dropdown in Selenium?
- How to call a non-static method of an abstract class from a static method in java?
- How will you separate iron pins from sand?
- How will you separate water from mustard oil?
- How to select an item from a dropdown list using Selenium WebDriver with java?
