RadioButton and CheckBox in Selenium WebDriver

0


we will use the CSS selector and click() mostly in the case of RadioButton.
<input type="radio" name="r1" value="Male" >Male
<input type="radio" name="r1" value="FeMale" >FeMale
driver.findElement(By.cssSelector("input[value='FeMale']")).click();
CheckBox:-
A checkbox is used to select multiple option CheckBox name always will be in array type or different name.
<input type="checkbox" name="chk1" value="C">C
<input type="checkbox" name="chk2" value="CPP">CPP
driver.findElement(By.name("chk1")).click()
<input type="checkbox" name="chk1[]" value="C">C
<input type="checkbox" name="chk1[]" value="CPP">CPP
driver.findElement(By.cssSelector("input[value='C']")).click();
Complete Script For RadioButton and CheckBox in WebDriver:-
package basic;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class RadioCheckBoxExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://shivaconceptsolution.com/test.html");
WebElement ele = driver.findElement(By.cssSelector("input[value='FeMale']"));
ele.click();
WebElement el1 = driver.findElement(By.name("chk2"));
for(int i=0;i<2;i++)
{
el1.click();
System.out.print(el1.isSelected());
}

}

}

Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)