Manual operation
- Select
- Check display status
- Check enabled status
- Check selected status
Selenium WebDriver Steps
package HandlingElementsInSelenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class HandlingRadioButton {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.gcrit.com/build3/create_account.php");
WebElement maleRadioButton = driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]"));
//Check Display status
boolean status = maleRadioButton.isDisplayed();
System.out.println("RadioButton is displayed :- "+status);
//Check enabled status
status = maleRadioButton.isEnabled();
System.out.println("RadioButton is enabled :- "+status);
//Check selected status
status = maleRadioButton.isSelected();
System.out.println("RadioButton is selected :- "+"CheckBox is selected :- "+status); //False
//Click to Select
maleRadioButton.click();
Thread.sleep(3000);
status = maleRadioButton.isSelected();
System.out.println("RadioButton is selected :- "+"CheckBox is selected :- "+status); //true
driver.close();
}
}
Next