How to select multiple options from a dropdown list using Actions class in Selenium

0 votes
How to select multiple options from a dropdown list using Actions class in Selenium?
Jul 8, 2019 in Selenium by Renu
5,293 views

1 answer to this question.

0 votes

Hey Renu, you can use Actions class provided by Selenium, to select multiple options from a dropdown. Actions class interact with keyboard and mouse activities and you can select multiple option by pressing Ctrl and click on options. Checkout the following lines of code to understand better:

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 select1 = driver.findElement(By.xpath("//option[@value='Volvo']"));
        WebElement select2 = driver.findElement(By.xpath("//option[@value='Saab']"));

        Actions action = new Actions(driver);
        action.keyDown(Keys.CONTROL).click(select1).click(select2).build().perform();

    }

}
answered Jul 8, 2019 by Abha
• 28,000 points

Related Questions In Selenium

0 votes
1 answer

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

Hey Priyansh, you can select multiple options ...READ MORE

answered Jul 8, 2019 in Selenium by Anvi
• 14,130 points
1,287 views
0 votes
3 answers

How to print text from a list of all web elements with same class name in Selenium?

Try using List <WebElement> to access all similar elements ...READ MORE

answered Dec 16, 2020 in Selenium by Roshni
• 10,420 points
27,287 views
0 votes
1 answer

How to scroll up/down a page using Actions class in Selenium?

Hi Naetik, you can use Actions class ...READ MORE

answered Jul 4, 2019 in Selenium by Anvi
• 14,130 points
11,142 views
0 votes
0 answers
0 votes
2 answers

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,520 points
4,630 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,474 views
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,890 points
3,303 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2, 2020 in Selenium by Sri
• 3,010 points
3,904 views
0 votes
1 answer

Can I select multiple options from a dropdown using Python Selenium webdriver?

Hi Dhwani, you can use following code ...READ MORE

answered Jul 30, 2019 in Selenium by Abha
• 28,000 points
1,925 views
0 votes
1 answer

How to get all options of a dropdown on a webpage using Selenium Webdriver?

Hey Joel, you can use following lines ...READ MORE

answered Jul 15, 2019 in Selenium by Abha
• 28,000 points
969 views