Hnadling webtable using web driver



//Handling WebTable with verifications

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class WebTable_SalesForce {
      
       WebDriver driver;
       @Test
       public void test() {
              driver=new FirefoxDriver();
              driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
              driver.get("http://www.salesforce.com");
              driver.findElement(By.id("button-login")).click();
              driver.findElement(By.id("username")).sendKeys("manu.immadi7373@gmail.com");
              driver.findElement(By.id("password")).sendKeys("selenium@123");
              driver.findElement(By.id("password")).sendKeys(Keys.ENTER);
              driver.findElement(By.xpath("//ul[@id='tabBar']/li[5]/a")).click();
              driver.findElement(By.xpath("//form[@id='hotlist']/table/tbody/tr/td[2]/input")).click();
              String firstName="Pavan";
              String lastName="Kalyan";
              String company="Tollywood";
              driver.findElement(By.id("name_firstlea2")).sendKeys(firstName);
              driver.findElement(By.id("name_lastlea2")).sendKeys(lastName);
              driver.findElement(By.id("lea3")).sendKeys(company);
              driver.findElement(By.xpath("//td[@id='bottomButtonRow']/input")).click();
              driver.findElement(By.xpath("//ul[@id='tabBar']/li[5]/a")).click();
             
              driver.findElement(By.xpath("//input[@name='go' and @value='Run Report']")).click();
              String xpath_Start="//*[@id='fchArea']/table/tbody/tr[";
              String xpath_End="]/td[1]";
              boolean recordfound=false;
              int i=2;
              while(isElementPresent(xpath_Start+i+xpath_End))
              {
                     String fname=driver.findElement(By.xpath(xpath_Start+i+xpath_End)).getText();
                     if(fname.equals(firstName)) {
                           //check the lastname
                           String lastnamecol=xpath_Start + i + xpath_End.replace("td[1]","td[2]");
                           String lname=driver.findElement(By.xpath(lastnamecol)).getText();
                           if(lname.equals(lastName)) {
                                  System.out.println("Both are same " +firstName + lastName);
                                  recordfound=true;
                                  i++;
                                  break;
                           }
                     }
              }
       Assert.assertTrue(recordfound, "Record NotAvilable");
              }
       public boolean isElementPresent(String objxpath) {
              int count = driver.findElements(By.xpath(objxpath)).size();
              if(count==0)
                     return false;
              else
                     return true;
       }
      
}