DeSelect all method is used to deSelect all the selected options at a time.It doesn’t take any argument and it doesn’t return anything.
# deselect_all ms_options.deselect_all()
Example:
Deselect_all_options.py
from selenium import webdriver
import time
from selenium.common.exceptions import ElementNotVisibleException, NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe")
driver.get("http://www.dummypoint.com/seleniumtemplate.html")
time.sleep(2)
wait = WebDriverWait(driver, 25, poll_frequency=1,
ignored_exceptions=[ElementNotVisibleException, NoSuchElementException])
ele = wait.until(ec.presence_of_element_located((By.ID, "multiselect")))
# import the Select class
# Create the object for Select class
ms_options = Select(ele)
# Click by Index
ms_options.select_by_index(1)
# Click by Value
ms_options.select_by_value("mOptionTWo")
# Click by Text
ms_options.select_by_visible_text("mOption3")
time.sleep(2)
# deselect_all
ms_options.deselect_all()
time.sleep(5)
driver.quit()