package scripts;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Rowcount {
public WebDriver driver;
@Test()
public void markets() throws Throwable
{
//Here give the company name
String companyName="Agro Dutch";
int count=1;
driver.get("http://content.icicidirect.com");
driver.findElement(By.xpath("//div[@id=\'topNavLv1\']/ul/li[3]/a")).click();
driver.findElement(By.xpath("//a[@id=\'M_Stats\']")).click();
WebElement table=driver.findElement(By.xpath("//table[@id=\'gridSource\']/tbody")) ;
//get total number of rows
List<WebElement> rows=table.findElements(By.tagName("tr"));
for(WebElement r : rows){
List<WebElement> colItems=r.findElements(By.tagName("td"));
String frstelement =colItems.get(0).getText();
if(!frstelement.isEmpty())
{
if(frstelement.equalsIgnoreCase(companyName))
{
break;
}
}
else
{
driver.findElement(By.xpath("//*[@id=\'gridSource\']/tfoot/tr/td[3]")).click();
count++;
}
count++;
}
System.out.println("Row number of " + companyName + " is " +count);
}
@BeforeClass
public void beforeClass() {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
}
@AfterClass
public void afterClass() {
driver.quit();
}
}