How to Handle Dropdowns in Selenium: Select Class Methods + Easier Katalon Approach
Learn with AI In this article, we β ll quickly cover those core Selenium commands and then demonstrate how Katalon Studio streamlines the same summons - rental you charm a dropdown with Spy Web and select pick using built-in keywords likeselectOptionByValue or selectOptionByIndex, so you can automatise dropdown interactions without pen boilerplate codification, & nbsp; but inaugural ... In web coating, a dropdown menu (also called a dropdown tilt) is a graphical control element that lets users pick one option from a list. When inactive, it shows a single selected value. When clicked, it expands to display all useable pick. A dropdown is stage as follows in HTML: & lt;! DOCTYPE html & gt; The Selectclass ply convenient method to interact with& lt; select & gt;HTML elements. You must first locate the dropdown element, so useSelectto select or deselect items. & nbsp; Select dropdown = new Select (driver.findElement (By.id(`` cars ''))); What it execute: This code selects the option at index 2, which corresponds to the third option in the list. Select all options that display text matching the argument. Select dropdown = new Select (driver.findElement (By.id(`` machine ''))); What it does:The code chance the dropdown by its ID, wraps it with the ` Select ` class, and selects the choice with displayed text tally `` Audi ''. Select all selection that hold a value matching the argument. Select dropdown = new Select (driver.findElement ([By.id] What it does:The code selects the choice withvalueattribute as `` saab ''. Pro tip: Tools like SUSA can handle this autonomously β upload your app and get results without writing a single test script. Clear all selected items. Note that this method but works if the dropdown allows a multi-select dropdown. Example Java code: & nbsp; dropdown.deselectAll (); Katalon Studio provides built-in keywords for the Select class that simplify dropdown handling and automatise your testing workflow. & nbsp; π Learn more in our corroboration: Step 1. In your test project, open the Spy Web & nbsp; tool. Step 3. ClickStartto establish your session. Navigate your pointer to the dropdown and right-click & gt;Capture Object. The object we captured is a& lt; select & gt;& nbsp; HTML element, and its XPath attributes are exhibit in theObject Spy& nbsp; dialog. & nbsp; With the objects you have capture, you can start creating test steps with Katalon Studio built-in keywords. Open your test event in theManualvista, make a examination cause using theWebUI.selectOptionByValuekeyword that finds thevalue= '' saab β WebUI. * openBrowser * (``) If you want to use another keyword, for exampleWebUI.selectOptionByIndex, try: Handling dropdowns is straightforward with Selenium β sSelectclass - just locate the& lt; select & gt;element and call methods likeselectByIndex, selectByVisibleText, or selectByValue - but maintaining those scripts can become tedious over clip. Katalon Studio streamlines the like workflow by letting you capture the dropdown with Spy Web and so call keywords likeselectOptionByValueor selectOptionByIndexwithout writing extra boilerplate. Whether you prefer total control through Selenium code or a faster, low-code approach in Katalon, both paths ensure your dropdown interactions stay reliable and easygoing to maintain. A dropdown menu (or dropdown list) is an HTML& lt; select & gt;element that allows user to choose one (or multiple) choice from a obscure list. In mechanisation, you interact with dropdowns by locating the& lt; select & gt;element and choosing one of its& lt; option & gt;children, rather than clicking each selection manually. Selenium β s Select class wraps any & lt; select & gt; element and exposes method like selectByIndex (int index), selectByVisibleText (String schoolbook), and selectByValue (String value). By employ these methods, you can reliably prefer the desired option without pen low-level click or JavaScript code to open and cull from the list. selectByVisibleText (`` Label '')is best when you know the precise text evidence to user (e.g., β Audi β). selectByValue (`` valueAttr '')works when you know the& lt; alternative value= '' ... '' & gt;attribute (e.g., value= β saab β), which can be more stable if display text modification. selectByIndex (2)selects the option at that zero-based place. It β s quick but brittleβif the order of options shifts, your index can point to the wrong choice. For & lt; quality multiple= '' true '' & gt;elements, you can useSelectmethods likeselectByVisibleText (), selectByValue (), or selectByIndex ()multiple times to pick more than one choice. To brighten all selected items, calldeselectAll (). Remember, deselect method only work on multi-select dropdowns. In Katalon Studio, you capture the& lt; select & gt;element once with Spy Web, store it as a Test Object, and so name built-in keywords likeWebUI.selectOptionByValue (testObject, `` saab '', true) or WebUI.selectOptionByIndex (testObject, 2). This eliminates boilerplate codeβno need to instantiate aSelectobjective in hand. Katalon handles locator stability and waits automatically, so you can publish fewer line and maintain tests more well. | Upload your APK or URL. SUSA explores like 10 real users β finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users β finds bugs, accessibility violations, and security issues. No scripts.How to Handle Dropdowns in Selenium: Quality Class Methods + Easier Katalon Approach
What is dropdown in Selenium?
& lt; html & gt;
& nbsp; & lt; caput & gt;
& nbsp; & nbsp; & lt; meta charset= '' UTF-8 '' / & gt;
& nbsp; & nbsp; & lt; title & gt; Select Element Example & lt; /title & gt;
& nbsp; & lt; /head & gt;
& nbsp; & lt; body & gt;
& nbsp; & nbsp; & lt; h1 & gt; The select element & lt; /h1 & gt;
& nbsp; & nbsp; & lt; p & gt; The select element is used to create a drop-down list. & lt; /p & gt;
& nbsp; & nbsp; & lt; sort action= '' /action_page.php '' & gt;
& nbsp; & nbsp; & nbsp; & lt; label for= '' cars '' & gt; Choose a car: & lt; /label & gt;
& nbsp; & nbsp; & nbsp; & lt; choice name= '' automobile '' & gt;
& nbsp; & nbsp; & nbsp; & nbsp; & lt; choice value= '' volvo '' & gt; Volvo & lt; /option & gt;
& nbsp; & nbsp; & nbsp; & nbsp; & lt; selection value= '' saab '' & gt; Saab & lt; /option & gt;
& nbsp; & nbsp; & nbsp; & nbsp; & lt; option value= '' opel '' & gt; Opel & lt; /option & gt;
& nbsp; & nbsp; & nbsp; & nbsp; & lt; option value= '' audi '' & gt; Audi & lt; /option & gt;
& nbsp; & nbsp; & nbsp; & lt; /select & gt;
& nbsp; & nbsp; & nbsp; & lt; br / & gt; & lt; br / & gt;
& nbsp; & nbsp; & nbsp; & lt; input type= '' submit '' value= '' Submit '' / & gt;
& nbsp; & nbsp; & lt; /form & gt;
& nbsp; & nbsp; & lt; p & gt;
& nbsp; & nbsp; & nbsp; Click the `` Submit '' button and the form-data will be sent to a page on
& nbsp; & nbsp; & nbsp; the server name `` action_page.php ''.
& nbsp; & nbsp; & lt; /p & gt;
& nbsp; & lt; /body & gt;
& lt; /html & gt;What is Select class in Selenium?
Common & lt; prime & gt;class method
1. selectByIndex ()
Select the choice at the given indicant. the Index starts from ` 0 `.
Example Java code:
dropdown.selectByIndex (2); 2. selectByVisibleText ()
Example Java code:
dropdown.selectByVisibleText (`` Audi '');3. selectByValue ()
Example Java code:
dropdown.selectByValue (`` saab '');4. deselectAll ()
Handle dropdown with Katalon Studio
Let β s give it a try! First we β ll need to capture some objects that we can use in the test case.
Capture objects with Spy Web
Step 2. Provide a link in the URL battleground. Here we β re using thehttps: //www.w3schools.com/tags/tryit.asp? filename=tryhtml_select site that contains a drop-down list.
HTML element by its XPath in Katalon Studio '' srcset= '' https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=496 & amp; height=711 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 496w, https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=992 & amp; height=1422 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 992w, https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=1488 & amp; height=2133 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 1488w, https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=1984 & amp; height=2844 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 1984w, https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=2480 & amp; height=3555 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 2480w, https: //katalon.com/hs-fs/hubfs/Screenshot % 202025-05-19 % 20at % 2013.54.08.png? width=2976 & amp; height=4266 & amp; name=Screenshot % 202025-05-19 % 20at % 2013.54.08.png 2976w '' sizes= '' (max-width: 992px) 100vw, 992px '' >
Click Save& nbsp; & gt;OK in the Add Element to Object Repository dialog.
Use Katalon built-in keywords
You can essay it out with this handwriting:
WebUI. * navigateToUrl * ('https: //www.w3schools.com/tags/tryit.asp? filename=tryhtml_select ')
WebUI. * selectOptionByValue * (* findTestObject * ('Object Repository/Page_W3Schools/select_Cars '),
'saab ', * * true * *)
WebUI. * wait * (3)
WebUI. * closeBrowser * ()WebUI.selectOptionByIndex (findTestObject ('Object Repository/Page_W3Schools/select_Cars '), 2, FailureHandling.STOP_ON_FAILURE)Conclusion
Frequently asked questions
What is a dropdown menu in web automation screen?
How does Selenium β s Select class simplify dropdown handling?
When should I use selectByVisibleText () vs. selectByValue () vs. selectByIndex ()?
How do I manage a multi-select dropdown in Selenium?
How does Katalon Studio streamline dropdown automation compared to raw Selenium code?
Automate This With SUSA
Test Your App Autonomously