Selenium-drop-down

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

セレン-ドロップダウンインタラクション

このセクションでは、ドロップダウンボックスと対話する方法を理解します。 「selectByVisibleText」または「selectByIndex」または「selectByValue」メソッドを使用してオプションを選択できます。

[[1]] また、ドロップダウンボックスが選択/有効化/表示されているかどうかを確認できます。

selenium_ide_182

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

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

     //Selecting an item from Drop Down list Box
      Select dropdown = new Select(driver.findElement(By.id("ccompound")));
      dropdown.selectByVisibleText("continuously");

     //you can also use dropdown.selectByIndex(1) to select second element as
     //index starts with 0.
     //You can also use dropdown.selectByValue("annually");

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

      driver.close();
   }
}

出力

実行すると、指定された値でドロップダウンが設定され、コマンドの出力がコンソールに表示されます。

selenium_ide_184