December 3, 2010

Verify Radio button is checked or not

Here i am writing steps how to verify the Radio button is checked or not?



package test;


import com.thoughtworks.selenium.*;


import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Radiobutton {
public Selenium selenium;
public SeleniumServer seleniumserver;


@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://");
seleniumserver.start();
selenium.start();
}


@Test
public void testRadiobutton() throws Exception {
        selenium.open("http://www.google.co.in/");
selenium.click("link=Language Tools");
selenium.waitForPageToLoad("30000");
//Click the second radio button. I used xpath to identify this element bcs the radio button does not have ID...
selenium.click("//span[@id='clirms']/input");
if(selenium.isChecked("//span[@id='clirms']/input"))
{
System.out.println("Radio button Specific languages checked");
}
else
{
System.out.println("Radio button Specific languages is not checked");
}
Thread.sleep(10000);

}


@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();


}
}






No comments:

Post a Comment