Thursday 26 June 2014

downdown to excel

package prgs;

import java.awt.Label;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class ebaytoexcel {
    public WebDriver driver;
    FileInputStream fi;
    Workbook w;
    Sheet s;
    FileOutputStream fo;
    WritableWorkbook  wb;
    WritableSheet so;
   
  @Test
  public void f()  throws Exception{
      driver.findElement(By.xpath("//select[@id='gh-cat']")).click();
      Thread.sleep(5000);
   
     
     List<WebElement> str1= new Select(driver.findElement(By.id("gh-cat"))).getOptions();
      System.out.println(str1.size());
   
   
     fo=new FileOutputStream("C:\\Documents and Settings\\admin\\Desktop\\eclipse\\d\\sari\\os\\ebay1.xls");
      wb=Workbook.createWorkbook(fo);
      so=wb.createSheet("abc",0);
   
      for(int i=0;i<str1.size();i++){
          System.out.println(str1.get(i).getText());
          jxl.write.Label ca=new jxl.write.Label(0,i,str1.get(i).getText());
             so.addCell(ca);
      }
   
          
     wb.write();
     wb.close();;
   
     
  }
  @BeforeTest
  public void beforeTest() {
      driver=new FirefoxDriver();
      driver.get("http://ebay.in");
  }

  @AfterTest
  public void afterTest() {
  }

}

No comments:

Post a Comment