How can I perform multiple selection of options in a dropdown using Select class in Selenium?

0 votes
How can I perform multiple selection of options in a dropdown using Select class in Selenium?
Jul 8 in Selenium by Priyansh
47 views

1 answer to this question.

0 votes

Hey Priyansh, you can select multiple options from a dropdown using Select class. Selenium provides Select class to perform various operations on a dropdown. Below code automate selection of multiple options with the help of Select class:

public class MultiSelectDropdown {

    WebDriver driver;

    @Test

    public void testApp() {

        System.setProperty("webdriver.chrome.driver",  "D:\SeleniumDrivers\chromedriver.exe");

        driver = new ChromeDriver();

        driver.get("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple");

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        WebElement selectList = driver.findElement(By.xpath("//select[@name='cars']"));

        Select select = new Select(selectList);

        select.selectByVisibleText("Volvo");

        select.selectByVisibleText("Saab");

    }

}
answered Jul 8 by Anvi
• 11,690 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
402 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
754 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
400 views
0 votes
1 answer
0 votes
1 answer

How can I clear the text in a text box using Selenium WebDriver?

Hello Akriti, you can clear the text ...READ MORE

answered May 29 in Selenium by Anvi
• 11,690 points
134 views