Quality Testing

Quality is delighting customers

How to read data from web page and insert that data in to the excel....?

Views: 234

Reply to This

Replies to This Discussion

Hi Ram,

Please follow the below steps:


1. First we read data from webpage and save it in any string input.


2. Create excel report in your local drive and write data(read from web page in step 1) into excel spreadsheet.


You can refer below code for more details:


  void readDataFromWebAndInsertIntoExcel() throws FileNotFoundException, IOException, InvalidFormatException {


         WebDriver driver = new FirefoxDriver();

         driver.get("http://newtours.demoaut.com/"); // Open website from where we need to read data

         String input =

driver.findElement(By.cssSelector("form[name='home'] font b")).getText(); // Get any input value from webpage

         InputStream inp = new FileInputStream("D:\\Selenium\\Data.xlsx");

         Workbook wb = WorkbookFactory.create(inp);

         Sheet sheet = wb.getSheetAt(0);

         Row row = sheet.createRow(0);

         Cell c = null;

         c = row.createCell(0);

         c.setCellValue(input); // insert input value in 0th row and 0th column of spreadsheet.

         FileOutputStream fileOut = new FileOutputStream("D:\\Selenium\\Data.xlsx");




Please check the page any for test automation services.



TTWT Magazine





© 2018   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service