Check radio buttons and checkboxes

/**
 * Un/Check radio buttons and checkboxes.
 * 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 Check
{
  private DefaultSelenium m_oBrowser = null;
 
  public static void main(String[] args)
  {
    Check oCheck = new Check();
 
    // Un/Check radio buttons and checkboxes.
    oCheck.runExamples();
  }
 
  // Constructor
  public Check()
  {
    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/radio_checkbox.html"); // Open the webpage.
  }
 
  // Un/Check radio buttons and checkboxes.
  public void runExamples()
  {
    // Radio Button: Check Monday using XPATH locator.
    this.m_oBrowser.check("xpath=//input[@value='Mon']"); 
 
    // Checkbox: Uncheck Apple using CSS selector.
    this.m_oBrowser.uncheck("css=input[name='apple']"); 
 
    // Checkbox: Check Orange using CSS selector.
    this.m_oBrowser.check("css=input[name='orange']"); 
 
    //this.m_oBrowser.stop(); // Close Selenium.
  }
}
AttachmentSize
HTML icon radio_checkbox.html1.24 KB