Created
May 30, 2015 02:45
-
-
Save simplytunde/8cff6d5321c3be553194 to your computer and use it in GitHub Desktop.
Selenium: Multiselect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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