from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get('url') select = Select(driver.find_element_by_id('fruits01')) # select by visible text select.select_by_visible_text('Banana') # select by value select.select_by_value('1')
Here is what the above code is Doing:
1. It’s creating a Select object by passing the element to the Select constructor.
2. It’s selecting the option with the value “1” by calling the select_by_value() method.
3. It’s selecting the option with the value “Banana” by calling the select_by_visible_text() method.