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.
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_index()
Step-by-step approach:
- Import webdriver from selenium module.
Python3
from selenium import webdriver
|
- Import Select class module.
Python3
from selenium.webdriver.support.ui import Select
|
- Using a web page for drop down list(example: URL).
- Navigate the id of option bar.

- In html, index starts from 0. Here we will select index value 2 for id RESULT_RadioButton-9.
Below is the complete program of the above approach:
Python3
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
x = driver.find_element_by_id( 'RESULT_RadioButton-9' )
drop = Select(x)
drop.select_by_index( 2 )
time.sleep( 4 )
driver.close()
|
Output:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
11 Oct, 2020
Like Article
Save Article