How to Select Value from DropDown using Java Selenium Webdriver? Last Updated : 01 Oct, 2024 Comments Improve Suggest changes Like Article Like Report In web Automation testing, the common task is Selecting the Dropdowns. Selenium Webdriver mainly used for Interacting to the Web-Elements. Selecting the Web-Elements from the dropdowns is a needed for the interaction to the browser.In these guide we will going through the process of selecting the dropdowns from the menu with using the Selenium WebDriver Automation.Example to Select Value from DropDown using Java Selenium WebdriverHere is the example to Select Value from DropDown using Java Selenium Webdriver: Java package seleniumpractice; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; public class DropDown { public static void main(String[] args) { // Set the path for ChromeDriver System.setProperty( "webdriver.chrome.driver", "path/to/chromedriver"); // Update this path // Creating an instance of Chrome driver WebDriver driver = new ChromeDriver(); try { // Launching URL driver.get("https://demoqa.com/select-menu"); // Maximizing window driver.manage().window().maximize(); // Selecting the dropdown element by locating // its id Select select = new Select( driver.findElement(By.id("oldSelectMenu"))); // Selecting an option by its value System.out.println( "Select the Option by value 6"); select.selectByValue("6"); System.out.println( "Selected value is: " + select.getFirstSelectedOption() .getText()); } catch (Exception e) { e.printStackTrace(); } finally { // Close the browser driver.quit(); } } } Explanation Package: Defines the package as selenium practice.Imports: Brings in necessary Selenium classes..Main Class: DropDown contains the main method.Set ChromeDriver Path: Specifies the location of chromedriver.exe.Initialize WebDriver: Creates a new Chrome browser instance.Open URL: Navigates to the demo webpage.Maximize Window: Maximizes the browser window.Select Dropdown: Locates the dropdown by ID.Select Option: Chooses the option with value "6".Print Selected Value: Displays the selected option's text.Close Browser: Quits the browser after execution.Output OutputConclusionMastering the Automation on the dropdowns using Selenium WebDriver. By using the Class method which is SelectVisibleText, selectByIndex, or selectByValue with these you can easily interact with the Dropdowns in any websites. and these will be used for the interaction to the browser. Comment More infoAdvertise with us Next Article How to Select Value from DropDown using Java Selenium Webdriver? S sunilgacd6r Follow Improve Article Tags : Software Testing Similar Reads How to Select Date from Datepicker in Selenium Webdriver using Java? In the world of web automation, selecting a date from a datepicker is a common task, especially for applications that involve date selection, such as booking systems, forms, and reservations. Selenium WebDriver is a powerful tool for automating web browsers, and when combined with Java, it provides 3 min read How to Take a Screenshot in Selenium WebDriver Using Java? Selenium WebDriver is a collection of open-source APIs used to automate a web application's testing. To capture a screenshot in Selenium, one must utilize the Takes Screenshot method. This notifies WebDriver that it should take a screenshot in Selenium and store it. Selenium WebDriver tool is used t 3 min read 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 2 min read How to Drag and Drop an Element using Selenium WebDriver in Java? Selenium is an open-source web automation tool that supports many user actions to perform in the web browser. Automating a modern web page that has a drag and drop functionality and drag and drop is used to upload the files and so many user activities. so to perform the drag and drop actions the sel 2 min read How to Get Selected Value in Dropdown List using JavaScript? A dropdown list is an HTML element that allows users to select one option from a list of options. The <select> and <option> tags are used to create dropdown lists in HTML. In this article, we will see how to get selected value from dropdown list using JavaScript.Basic HTML Structure for 2 min read How to Click on a Hyperlink Using Java Selenium WebDriver? An open-source tool that is used to automate the browser is known as Selenium. Automation reduces human effort and makes the work comparatively easier. There are numerous circumstances in which the user wants to open a new page or perform a certain action with the click of the hyperlink. In this art 4 min read Reading JavaScript variables using Selenium WebDriver In web automation testing, interacting with JavaScript variables on a webpage can be essential for validating specific conditions. Selenium WebDriver provides a way to execute JavaScript directly on the browser using the `executeScript()` method. This feature allows us to read JavaScript variables a 2 min read Key press in (Ctrl+A) Selenium WebDriver using java Selenium WebDriver is a powerful tool for automating web applications, and it offers various ways to simulate user actions such as clicking, typing, and even pressing keyboard shortcuts. One of the common actions is selecting all text or elements on a page using the "Ctrl+A" key press. This is usefu 3 min read How to get text from the alert box in java Selenium Webdriver? In Automation testing, we can capture the text from the alert message in Selenium WebDriver with the help of the Alert interface. By default, the webdriver object has control over the main page, once an alert pop-up gets generated, we have to shift the WebDriver focus from the main page to the alert 2 min read File Upload using Selenium WebDriver and Java Robot Class File uploads are a common task in web automation, and handling them effectively can be crucial for testing file-related functionalities. While Selenium WebDriver provides a straightforward way to interact with file upload elements, sometimes the built-in methods fall short. In such cases, combining 3 min read Like