Redeem Now
Read More
Read now
Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    hyperlocal-marketplace-guide

    Handling Drop Down List with Selenium WebDriver

    Drop Down And Multi-Select list is the set of HTML fields that we commonly interact with.So, In order to handle drop-down and multi-select list with Selenium WebDriver, it is essential to use Select class, It is the Webdriver class which is the part of the selenium package, provides the implementation of the HTML SELECT tag.

    We need to Import the below package.

    Select is an ordinary class, so it’s object is also created by a New keyword with regular class creation syntax.
    Standard syntax of Select Class is as:-

    For a better understanding on using the <Select> class, refer at the below Java code.

    WebDriver provides three ways to select an option from the drop-down menu. So, once you have initialized the <Select> object then, you can access all the methods used on the drop-down and Multi-Select list.

    Types of Select Methods:

    1. selectByVisibleText Method
    2. selectByIndex Method
    3. selectByValue Method

    Here’s the illustration of the dropdown operation with following HTML Sample Code.

    SelectByVisibleText Method

    Selects options that match the input text in the argument, it will match the visible text in the dropdown field.

    SYNTAX:-

    Here’s the Sample code to select the value based on the visible text.

    selectByIndex Method

    Selects the option based on the index value.

    SYNTAX:-

    Here’s the Sample code to select the value based on the Index value.

    selectByValue Method

    Selects the option whose value attribute provided by the user in the specified parameter.

    SYNTAX:-

    Here’s the Sample code to select the value based on the Value.

    This is all about Handling Drop-Down list with Selenium WebDriver.

    Thanks for reading this blog 🙂

    Happy testing!!

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close