首页 > 代码库 > webdriver---API---(java版)

webdriver---API---(java版)

操作单选框、复选框

<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=http://www.mamicode.com/‘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;
              }
          }
      }

 

webdriver---API---(java版)