1from selenium import webdriver
2from selenium.webdriver.support.ui import Select
3
4driver = webdriver.Firefox()
5driver.get('url')
6
7select = Select(driver.find_element_by_id('fruits01'))
8
9# select by visible text
10select.select_by_visible_text('Banana')
11
12# select by value
13select.select_by_value('1')
1# Just found a very simple solution for this annoying problem
2# Been looking around for days just to solve it, Selecting dropdowns without Select class
3
4# Find your dropdown element by the following, finds the element in the dropdown named BRA
5Dropdown_Element = driver.find_element(By.XPATH, "//*[text()='BRA']").click()
6
7# Store the ActionChains class inside the actions variable
8actions = ActionChains(driver)
9
10# Click on the element using the click(on_element=)
11actions.click(on_element=Dropdown_Element)
12time.sleep(2)
13actions.perform()
14
15# Hopes this helped :)
11-Select dropdowns:are created by using <select> tag in HTML
22-HTML dropdowns:these are the dropdowns that are created NOT USING <select>
3These dropdowns are handled just like any other webElement.
4Select select = new Select(driver.findElement(LOCATOR));
51-selectByVisibleText(String arg);
62-byIndex(int arg);
73-byValue:
8.getFirstSelectedOption() .getOptions();
9.getAllSelectedOptions();.deSelectAll();