document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package scripts;
  2.  
  3. import java.util.List;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.WebElement;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10. import org.testng.annotations.AfterClass;
  11. import org.testng.annotations.BeforeClass;
  12. import org.testng.annotations.Test;
  13.  
  14. public class Rowcount {
  15.     public WebDriver driver;
  16.  
  17.     @Test()
  18.     public void markets() throws Throwable
  19.     {
  20.         //Here give the company name
  21.         String companyName="Agro Dutch";
  22.         int count=1;
  23.     driver.get("http://content.icicidirect.com");
  24.     driver.findElement(By.xpath("//div[@id=\'topNavLv1\']/ul/li[3]/a")).click();
  25.     driver.findElement(By.xpath("//a[@id=\'M_Stats\']")).click();
  26.     WebElement table=driver.findElement(By.xpath("//table[@id=\'gridSource\']/tbody")) ;
  27.     //get total number of rows
  28.     List<WebElement> rows=table.findElements(By.tagName("tr"));
  29.     for(WebElement r : rows){
  30.         List<WebElement> colItems=r.findElements(By.tagName("td"));                      
  31.         String frstelement =colItems.get(0).getText();
  32.         if(!frstelement.isEmpty())
  33.         {
  34.            
  35.             if(frstelement.equalsIgnoreCase(companyName))
  36.             {    
  37.                 break;
  38.             }
  39.         }
  40.         else
  41.         {
  42.             driver.findElement(By.xpath("//*[@id=\'gridSource\']/tfoot/tr/td[3]")).click();
  43.             count++;
  44.         }
  45.         count++;
  46.     }
  47.     System.out.println("Row number of " + companyName + " is " +count);
  48.  
  49.     }
  50.     @BeforeClass
  51.     public void beforeClass() {
  52.         driver = new FirefoxDriver();
  53.         driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  54.         driver.manage().window().maximize();
  55.     }
  56.  
  57.     @AfterClass
  58.     public void afterClass() {
  59.         driver.quit();
  60.     }
  61.  
  62. }
');