Selenium-radio-button

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

セレン-ラジオボタンの相互作用

このセクションでは、ラジオボタンと対話する方法を理解します。 'click’メソッドを使用してラジオボタンオプションを選択し、同じ 'click’メソッドを使用して選択を解除できます。

[[1]] ラジオボタンが選択されているか、有効になっているかを確認することもできます。

selenium_ide_178

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 an 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-payoff-calculatorl");
      driver.manage().window().maximize();

     //Click on Radio Button
      driver.findElement(By.id("cpayoff1")).click();
      System.out.println("The Output of the IsSelected " +
         driver.findElement(By.id("cpayoff1")).isSelected());
      System.out.println("The Output of the IsEnabled " +
         driver.findElement(By.id("cpayoff1")).isEnabled());
      System.out.println("The Output of the IsDisplayed " +
         driver.findElement(By.id("cpayoff1")).isDisplayed());

     //Close the Browser.
      driver.close();
   }
}

出力

実行すると、ラジオボタンが選択され、コマンドの出力がコンソールに表示されます。

selenium_ide_179