Scenario : Want to fetch Column name: Owner Name | Shared Held | Date from data grid of
website: nasdaq.com/symbol/ctsh/institutional-holdings
In date range say 01/01/2014 to 31/12/2014 or 01/01/2013to 31/12/2013
and want put it into excel sheet. please guide me on this.
==============
Code I designed this code to read data from data grid and all pages now am looking for solution for above mention Scenario.
public class table1 {
WebDriver driver = new FirefoxDriver();
protected static HSSFWorkbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
protected static HSSFSheet sheet1 = wb.createSheet("IHSharedHeld");
@BeforeTest
public void setup() throws Exception {
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("http://www.nasdaq.com/symbol");
driver.findElement(By.id("stock-search-text")).clear();
driver.findElement(By.id("stock-search-text")).sendKeys("BDC");
driver.findElement(By.id("stock-search-submit")).click();
JavascriptExecutor jsedown = (JavascriptExecutor)driver;
jsedown.executeScript("scroll(0, 250)");
//Click on holdings link.
driver.findElement(By.id("holdingslink")).click();
System.out.println("Action should counduct once ");
Thread.sleep(3000);
}
@AfterTest
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void print_data() throws Exception{
//locator for last page button
List<WebElement> lastPage = driver.findElements(By.xpath("html/body/div[4]/div[2]/div[9]/form/div[15]/div/ul/ul/li"));
System.out.println("Paging functionality");
for(int i=0; i<=(lastPage.size()); i++)
{
if (lastPage.size()>=0){
//locator for next page button
List<WebElement> nextPage = driver.findElements(By.id("quotes_content_left_lb_NextPage"));
if(nextPage.size() >= 0){
//Get number of rows In table.
int Row_count = driver.findElements(By.xpath(".//*[@id='quotes_content_left_pnlInsider']/table/tbody/tr")).size();
System.out.println("Number Of Rows = "+Row_count);
//Get number of columns In table.
int Col_count = driver.findElements(By.xpath(".//*[@id='quotes_content_left_pnlInsider']/table/tbody/tr[1]/td")).size();
System.out.println("Number Of Columns = "+Col_count);
//divided xpath In three parts to pass Row_count and Col_count values.
String first_part = ".//*[@id='quotes_content_left_pnlInsider']/table/tbody/tr[";
String second_part = "]/td[";
String third_part = "]";
//Used for loop for number of rows.
for (int k=1; k<=Row_count; k++){
//Used for loop for number of columns.
for(int j=1; j<=3; j++){
//Prepared final xpath of specific cell as per values of i and j.
String final_xpath = first_part+k+second_part+j+third_part;
//Will retrieve value from located cell and print It.
String Table_data = driver.findElement(By.xpath(final_xpath)).getText();
System.out.print(Table_data +" ");
excelLog(Table_data);
}
System.out.println("");
System.out.println("");
}
}
nextPage.get(0).click();
}
}
}
Now I want only write Owner Name | Shared Held | Date column data in to excel sheet in date range of
say 01/01/2014 to 31/12/2014 or 01/01/2013to 31/12/2013.
Please Help me on this topic