title: How to store a text field value and retrieve it later - Selenium Web Driver Using Java
body: <p>Need your help in Selenium Webdriver coding with Java.</p>
  
  <p>I have a scenario, where I create a Course name and submit it to the database and then later I need to search for the Course by the name I created it.
  Simply the work flow would be;
  1. Type the course name in text box (Here I'm randomly generating a string so it's not hard coded, I need to retrieve exactly what I typed here)
  2. Store the typed name
  3. In the search box type that name</p>
  
  <pre><code>private void createCurriculum() throws InterruptedException {
      selenium.open("http://url.com");
  
      driver.findElement(By.id("Text1")).clear();
      driver.findElement(By.id("Text1")).sendKeys("My Curriculum" + genData.generateRandomAlphaNumeric(10)); // Here I'm randomly generating the name, I need to retrieve what I type here in the next method
      //String curName = driver.findElement(By.id("Text1")).getAttribute("value"); 
      //I tried this but it didn't work
  
      Thread.sleep(300);
  }
  
  
  
  private void searchCurriculum(String curName) throws InterruptedException {
      selenium.open("http://url.com");
  
      driver.findElement(By.xpath("//div/input")).sendKeys("curName"); // Here I want to retireve what I previously generated. It's not working
      // . . .
  </code></pre>
  
  <p>Additionally in the main method, I have declared the variable too.</p>
  
  <pre><code>public class TestCaseCreateCurriculum {
     private Selenium selenium;
     private WebDriver driver;
     GenerateData genData;
  
     public String curName;
     // . . .
  </code></pre>
  
  <p>Could anybody help me to correct this code?</p>
  
  <blockquote>
    <p>This perfectly worked after modifying (thanks to Vageesh Bhasin)</p>
  </blockquote>
  
  <pre><code>driver.findElement(By.id("Text1")).sendKeys(curName = "My Curriculum" + genData.generateRandomAlphaNumeric(10));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>driver.findElement(By.xpath("//div/input")).sendKeys(curName);
  </code></pre>