Selenium-check-box

提供:Dev Guides
移動先:案内検索

セレン-チェックボックスの相互作用

このセクションでは、チェックボックスと対話する方法を理解します。 「クリック」メソッドを使用してチェックボックスを選択し、同じ「クリック」メソッドを使用してチェックを外すことができます。

[[1]] チェックボックスが選択/有効/表示されているかどうかも確認できます。

selenium_ide_180

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class webdriverdemo {
   public static void main(String[] args) throws InterruptedException {

      WebDriver driver = new FirefoxDriver();
     //Puts a Implicit wait, Will wait for 10 seconds before throwing exception
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

     //Launch website
      driver.navigate().to("http://www.calculator.net/mortgage-calculatorl");
      driver.manage().window().maximize();

     //Click on check Box
      driver.findElement(By.id("caddoptional")).click();

      System.out.println("The Output of the IsSelected " +
         driver.findElement(By.id("caddoptional")).isSelected());
      System.out.println("The Output of the IsEnabled " +
         driver.findElement(By.id("caddoptional")).isEnabled());
      System.out.println("The Output of the IsDisplayed " +
         driver.findElement(By.id("caddoptional")).isDisplayed());

      driver.close();
   }
}

出力

実行時には、クリックコマンドの後にチェックボックスがオフになり(デフォルトでチェックされているため)、コマンドの出力がコンソールに表示されます。

selenium_ide_181