Wednesday, 15 October 2014

How to get Text Box value

//How to get Text Box value

public class gettextvalue
{
  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://seleniumguru.blogspot.in/");
   
    //Maximize the browser
    driver.manage().window().maximize();

    // Enter value "selenium" in the first n
        driver.findElement(By.xpath("//*[@id='CustomSearch1_form']/form/table[1]/tbody/tr/td[1]/input  [1]")).sendKeys("selenium");

    // Get the text box from the application
    String result = driver.findElement(By.xpath("//*[@id='CustomSearch1_form']/form/table[1]/tbody/tr/td[1]/input[1]")).getAttribute("value");

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

No comments:

Post a Comment