Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
To select a value from a drop-down field using Selenium, use the Select class from the `selenium.webdriver.support.ui` module. Here's an example of the same:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
# create a new Chrome browser instance
driver = webdriver.Chrome()
# navigate to a web page with a dropdown field
driver.get("https://www.lambdatest.com")
# find the dropdown element by its ID
dropdown = Select(driver.find_element_by_id("dropdown-id"))
# select an option by visible text
dropdown.select_by_visible_text("Option 1")
# select an option by value
dropdown.select_by_value("option1")
# select an option by index
dropdown.select_by_index(0)
# close the browser
driver.quit()
To test a dropdown field in a website, you can create a new Chrome browser instance using `webdriver.Chrome()`. Then navigate to the website, find the dropdown field by its ID using `driver.find_element_by_id()`, and finally click on it.
To select an option from a dropdown, we create a Select object by passing it to the dropdown element to select an option from a dropdown. We can then choose an option from the dropdown by calling one of the following methods on the Select object: `select_by_index(i)` or `select_by_label(s)`.
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud