Skip to content

Instantly share code, notes, and snippets.

@simplytunde
Created May 30, 2015 02:45
Show Gist options
  • Save simplytunde/8cff6d5321c3be553194 to your computer and use it in GitHub Desktop.
Save simplytunde/8cff6d5321c3be553194 to your computer and use it in GitHub Desktop.
Selenium: Multiselect
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import java.util.concurrent.TimeUnit;
public class TestClass {
public static void main(String[] args){
TestClass t=new TestClass();
t.run();
}
public void run(){
WebDriver firefoxDriver=null;
try{
firefoxDriver=new FirefoxDriver();
firefoxDriver.get("http://davidstutz.github.io/bootstrap-multiselect/");
String elementID="example-getting-started";
JavascriptExecutor executor=(JavascriptExecutor) firefoxDriver;
executor.executeScript("document.getElementById('example-getting-started').setAttribute('style','display:visible')");
Select dropDown=new Select(firefoxDriver.findElement(By.id(elementID)));
dropDown.selectByIndex(0);
dropDown.selectByVisibleText("Onions");
dropDown.selectByIndex(3);
} catch(NoSuchElementException e){
}finally{
//firefoxDriver.quit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment