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.example.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");
}
}