Selenium-textbox

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

セレン-テキストボックスの相互作用

このセクションでは、テキストボックスを操作する方法を理解します。 'sendkeys’メソッドを使用して、テキストボックスに値を入力できます。 同様に、getattribute( "value")コマンドを使用してテキストボックスからテキストを取得することもできます。 次の例を見てください。

selenium_ide_177

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/percent-calculatorl");

     //Maximize the browser
      driver.manage().window().maximize();

     //Enter value 10 in the first number of the percent Calculator
      driver.findElement(By.id("cpar1")).sendKeys("10");

      Thread.sleep(5000);

     //Get the text box from the application
      String result = driver.findElement(By.id("cpar1")).getAttribute("value");

     //Print a Log In message to the screen
      System.out.println(" The Result is " + result);

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

出力

上記のスクリプトの出力は、次のように表示されます。

selenium_ide_183