How to select a drop-down menu value using Selenium in Python?
Prerequisite: Browser Automation Using Selenium
Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we will be using Python.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Requirement:
You need to download install chrome driver from here Click Here and set path.
Working with Drop-down list:
Initially you have to import the Select class and afterward you have to make the case of Select class. After making the case of Select class, you can perform select strategies on that occasion to choose the choices from dropdown list.
Importing Select class:
from selenium.webdriver.support.ui import Select
For selection:
drop=Select(driver.find_element_by_id(' ')
drop.select_by_value(" ")
Step-by-step approach:
- Import webdriver from selenium module.
Python3
# Import required modulefrom selenium import webdriver |
- Import Select class module.
Python3
# Importing Select classfrom selenium.webdriver.support.ui import Select |
- Using a web page for drop down list(example: URL).
- Navigate the id of option bar.

- Navigate options value in html web page.

Below is complete program of the above approach:
Python3
# Import required moduleimport timefrom selenium import webdriver # Import Select classfrom selenium.webdriver.support.ui import Select # Using chrome driverdriver = webdriver.Chrome() # Web page url # Find id of optionx = driver.find_element_by_id('RESULT_RadioButton-9')drop = Select(x) # Select by valuedrop.select_by_value("Radio-0")time.sleep(4)driver.close() |
Output:

