title: Unable to change value to element dynamically in Selenium Webdriver
body: <p>When I am running this code a runtime Exception is thrown by Compiler,</p>
  
  <pre><code>String ExistUser = driver.findElement(By.xpath(".//*@id='**UserBody']/tr[j]**/td[1]")).getText(); 
  </code></pre>
  
  <p>while when I changed j into 1, I get the output</p>
  
  <pre><code>String ExistUser = driver.findElement(By.xpath(".//*@id=**'UserBody']/tr[1]**/td[1]")).getText(); 
  </code></pre>
  
  <p>but I am unable to understand why it happens, can anyone please help me.</p>
  
  <pre><code>if (driver.findElements(By.xpath(".//*[@id='UserBody']/tr[1]/td[1]") ).size()!= 0)
  {
     int j;
     for (j=1 ; j&lt; 10; j++)
         {
           String ExistUser = driver.findElement(By.xpath(".//*@id='UserBody']/tr[j]/td[1]")).getText();
           //String value = ExistUser.getAttribute("value");
           System.out.println(ExistUser);
  
         }
  }
  </code></pre>