package webdriverTestNG;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterTest;
public class SelectDropDownValues {
WebDriver driver;
@Test
public void multiselect() throws InterruptedException{
driver.get("http://www.seleniumlearn.com/simple-program-select-and-multi-select-options");
Thread.sleep(2000);
Select listbox = new Select(driver.findElement(By.name("faculty")));
//To verify that specific select box supports multiple select or not.
if(listbox.isMultiple()) {
System.out.print("Multiple selections is supported");
listbox.selectByVisibleText("Biscuits"); // selectByVisibleText
Thread.sleep(2000);
listbox.selectByValue("Option5"); // selectByValue
listbox.selectByIndex(0); // selectByIndex
Thread.sleep(3000);
listbox.deselectAll(); //To deselect all selected options.
Thread.sleep(2000);
/*
String selectAll = Keys.chord(Keys.CONTROL, "a"); //To select all available options.
driver.findElement(By.name("faculty")).sendKeys(selectAll);*/
Actions act = new Actions(driver); //To select all available options.
act.sendKeys(Keys.chord(Keys.CONTROL,"a")).build().perform();
}
else
{
System.out.print("Not supported multiple selections");
}
}
@BeforeTest
public void beforeTest() {
driver=new FirefoxDriver();
// System.setProperty("webdriver.chrome.driver", "D:\\lib\\chromedriver.exe");
// driver=new ChromeDriver();
driver.manage().window().maximize();
}
@AfterTest
public void afterTest() {
}
}