操作单选框、复选框
<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; } } }
时间: 2024-11-02 23:27:37