操作单选框、复选框
<html> <body> <form> <input type="checkbox" name="fruit" value="berry"/>草莓</input> <br /> <input type="checkbox" name="fruit" value="watermelon"/>西瓜</input> <br /> <input type="checkbox" name="fruit" value="orange"/>橘子</input> </form> </body> </html>
WebElement radioOption=driver.findElement(By.xpath("//input[@value=‘berry‘]"));
if(!radioOption.isSelected()){
radioOption.click();
}
List<WebElement>fruits=driver.findElements(By.name("fruit"));
for(WebElement fruit : fruits){
if(fruit.getAttribute("value").equals("watermelon")){
if(!fruit.isSelected()){
fruit.click();
Assert.assertTrue(fruit.isSelected());
break;
}
}
}
原文:http://www.cnblogs.com/wangyinxu/p/6399065.html