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
11,746 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.example.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,140 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,150 points
3,249 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,480 points
87,803 views
0 votes
1 answer

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

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

answered Jul 5, 2019 in Selenium by Anvi
• 14,150 points
20,638 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,500 points
13,793 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,190 points
9,198 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,910 points
7,281 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 3, 2020 in Selenium by Sri
• 3,190 points
7,909 views
+1 vote
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 31, 2019 in Selenium by Abha
• 28,140 points
4,989 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,140 points
2,549 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP