Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Selecting a drop-down list by using the Selenium.select_by_visible_text() method in Python

  • Last Updated : 11 Oct, 2020

Selenium is an effective device for controlling an internet browser thru 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 can be running with Python.

Different methods of Select class:

 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

  • Selection an option from the dropdown menu by INDEX.
  • Selection an option from the dropdown by VISIBLE TEXT.
  • Selection an option from the dropdown menu by VALUE.

we are discussing on visible text method in the drop-down list.



The strategy chooses the alternative by its obvious choice label esteem. It acknowledges the noticeable content estimation of the choice tag and brings nothing back.

Requirement: You need to install chromedriver and set path. Click here to download.for more information follows this link.

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 the dropdown list.

from selenium.webdriver.support.ui import Select

 for selection by using

drop=Select(driver.find_element_by_id(‘ ‘)

drop.select_by_visible_text(” “)

Example: We will be doing the following:

  • Import selenium module
  • Import select class module
  • Using web page for drop down list (URL).
  • Navigate to the id of option bar.

Python3




# importing the modules
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
  
# using chrome driver
driver=webdriver.Chrome()
  
# web page url
  
# find id of option
x = driver.find_element_by_id('RESULT_RadioButton-9')
drop=Select(x)
  
# select by visible text
drop.select_by_visible_text("Afternoon")
time.sleep(4)
driver.close()

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!