title: How to pass value by reference in xpath where the values are imported from external excel sheet in selenium webdriver
body: <p>I am trying to automate a functional flow where I am adding a project and then confirming if it gets added successfully.
  My web form has 3 fields (say fld1, fld2, fld3). I created an external excel sheet from where fld1 fld2 and fld3 values are called and entered into the form and submit happens. The steps I am automating is:</p>
  
  <ol>
  <li>Step 1. Import fld1, fld2 and fld3 from excel sheet row 1 into the
  form (I am able to do this)</li>
  <li>Step 2. Submit it.(I am able to do this)</li>
  <li>Step 3. Check the project gets added.(Not able to do this one.)</li>
  <li>Step 4. Again perform step 1 with row 2 data and do step 2 and so
  on.</li>
  </ol>
  
  <p>The UI of the form1 is it has 3 fields say fld1, fld2, fld3 and a grid below these fields to show already added projects and once a project gets added it starts displaying in this grid as last row of the grid. Once we  import all 3 fields from excel sheet on form 1 and do submit, after click on submit an iframe window opens that shows % uploaded and once its uploaded 100% user needs to click on close button and iframe classes and user is on form 1 again and the project is added as the very last row of the grid. Till here I am able to automate.
  I want to check of project is added or no. For this I tried using assert but am not sure how to pass value by reference in xpath. If I hardcode it then the script fails for row 2 of excel sheet for second iteration.My question is how should I pass value by reference in either findElement By id or using assert condition.
  The code is here:</p>
  
  <pre><code>String projectName = null;
  WebDriverWait wait = new WebDriverWait( driver, 200);
  FileInputStream IPLinkFile = new FileInputStream(new File("xlsx sheet location"));
  XSSFWorkbook workbook = new XSSFWorkbook(TestIPLFile);
  XSSFSheet sheet = workbook.getSheet("Test");
  Iterator&lt;Row&gt; rowIterator = sheet.iterator();
  while (rowIterator.hasNext())
  {
    Row row = rowIterator.next();
    Thread.sleep(500);
    driver.findElement(By.id("InsertButtonID")).click();
    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("pname1ID")));
    Iterator &lt;Cell&gt; cellIterator = row.cellIterator();
    while (cellIterator.hasNext())
    {
      Cell cell = cellIterator.next();
      if (cell.getColumnIndex()==0)
      {
        driver.findElement (By.id("pname1ID")).clear();
        projectName = cell.getStringCellValue();
        driver.findElement (By.id("pname1ID")).sendKeys(cell.getStringCellValue());
      } else if(cell.getColumnIndex()==1)
      {
        Thread.sleep(500);
        driver.findElement(By.id("gvhost1ID")).clear();
        driver.findElement(By.id("gvhost1ID")).sendKeys(cell.getStringCellValue());
      } else if(cell.getColumnIndex()==2)
      {
        Thread.sleep(500);
        driver.findElement(By.id("gcTest1")).clear();
        driver.findElement(By.id("gcTest1")).sendKeys(cell.getStringCellValue());
      }
      else
      {
        break;
      }
    }
    driver.findElement(By.id("btnUpdateImportID")).click();
    Thread.sleep(10000);
    driver.switchTo().frame("TestImportTest");
    driver.findElement(By.id("form1"));
    driver.findElement(By.id("btnClose")).click();
    System.out.println("**********User uploaded IPLink Project successfully**********"+projectName);
    driver.navigate().refresh();
    Thread.sleep(500);
    driver.findElement(By.xpath("//div[@id = 'GridDataID']//td[contains(text(), 'TestAuto1')]"));
    System.out.println("**********User uploaded IPLTest Projects found**********"+projectName);
  }
  </code></pre>
  
  <p>I am using selenium with java and testNG.</p>