/**
* Select single/multiple options.
* Assume that you have Internet Explorer and Selenium Server is running on your
* computer on default port 4444. Otherwise, change accordingly in the constructor.
* @Author: Xuan Ngo
*/
import com.thoughtworks.selenium.DefaultSelenium;
public class Select
{
private DefaultSelenium m_oBrowser = null;
public static void main(String[] args)
{
Select oSelect = new Select();
// Select single/multiple options.
oSelect.runExamples();
}
// Constructor
public Select()
{
this.m_oBrowser = new DefaultSelenium("localhost", 4444, "*iexplore", "http://openwritings.net/");
this.m_oBrowser.start(); // Start Selenium.
this.m_oBrowser.open("http://openwritings.net/sites/default/files/select.html"); // Open the webpage.
}
// Select single/multiple options.
public void runExamples()
{
// Single Selection: Use ID locator and LABEL option locator to select July.
this.m_oBrowser.select("id=single-selection", "label=July");
// Multiple Selections: Use variations of locators to select February, August and November.
this.m_oBrowser.select("xpath=//select[@size='12']", "value=Feb"); // Select February
this.m_oBrowser.addSelection("css=select[id=multi-selections]", "index=7"); // and August.
this.m_oBrowser.addSelection("dom=document.getElementById('multi-selections')", "id=m_opt_10");// and November.
//this.m_oBrowser.stop(); // Close Selenium.
}
}