selenium webdriver 操作RadioButton
@Test public void testRadio() { WebDriver driver = ExplorerBase.IESetting(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } driver.manage().window().maximize(); driver.get(""); WebElement element = driver.findElement(By.id("sex_1")); element.click(); System.out.println(element.isSelected()); if (element.isSelected()) { System.out.println(1); System.out.println(element.getAttribute("value")); element = driver.findElement(By.id("sex_2")); element.click(); } /* * 选择某个单选项: bookMode.click(); * 清空某个单选项: bookMode.clear(); * 判断某个单选项是否已经被选择:bookMode.isSelected(); */ }