How to insert output values into the Excel through WebDriver.

3,595 views
Skip to first unread message

Yogesh Tyagi

unread,
Jan 13, 2014, 2:36:16 AM1/13/14
to seleniu...@googlegroups.com
Hi All,

Please help me out on bellow mentioned point:

How to insert output values into the Excel through WebDriver.



Regards,
Yogesh

vishnu

unread,
Jan 13, 2014, 5:10:16 AM1/13/14
to seleniu...@googlegroups.com
Remember, WebDriver is an API to interact with browser and just that, nothing to do with Excel parsing. Similarly there would be APIs to interact with Excel, choose the one based on your preferred programming language.

For example, for C# implementation you can take a look at NPOI.

Thanks,
Vishnu

rafiuddin shaik

unread,
Jan 13, 2014, 6:46:57 AM1/13/14
to seleniu...@googlegroups.com
Hi Yogesh!
I am putting up the workable code of extracting from the list

you might have to create a user name and password for this code to work
at salesforce.com

package com.cybersysit.demo;

import java.io.File;
import java.io.IOException;
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.openqa.selenium.support.ui.Select;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class JXL_ExcelWriter {

    /**
     * @learn selenium from cybersysit.com
     * @
     */
    WebDriver driver;
    public void launch_browser(){
        driver = new FirefoxDriver();
        driver.get("http://www.salesforce.com/in/?ir=1");
        driver.findElement(By.xpath("//*[@id='button-login']")).click();
        driver.findElement(By.xpath("//*[@id='username']")).sendKeys("username");
        driver.findElement(By.xpath("//*[@id='password']")).sendKeys("password");
        driver.findElement(By.xpath("//*[@id='Login']")).click();
    }
   
    public void populateList() throws IOException, RowsExceededException, WriteException{
        String filePath = "D:\\ChilakalagudaJava\\SalesForceDemo\\industryList.xls";
        File file = new File(filePath);
        WritableWorkbook workBook = Workbook.createWorkbook(file);
        WritableSheet sheet = workBook.createSheet("writework", 0);
       
       
       
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        //lead creation
        driver.findElement(By.xpath("//*[@id='Lead_Tab']/a")).click();
   
        //click new lead button
        driver.findElement(By.xpath("//*[@id='hotlist']/table/tbody/tr/td[2]/input")).click();
       
        WebElement listIndustry = driver.findElement(By.id("lea6"));
        Select selectIndustry = new Select(listIndustry);
        List <WebElement>listindustry = selectIndustry.getOptions();
        int column=0;
        for(int y=0;y<listindustry.size();y++){
            String listindust = listindustry.get(y).getText();
            System.out.println("industry List"+listindust);
            Label indLabel = new Label(column,y,listindust);   
            System.out.println("y ................."+y);
            sheet.addCell(indLabel);
       
           
        }
        workBook.write();
        workBook.close();
    }

    public static void main(String[] args) throws IOException, RowsExceededException, WriteException {
        // TODO Auto-generated method stub
        JXL_ExcelWriter Obj = new JXL_ExcelWriter();
        Obj.launch_browser();
        Obj.populateList();
       
    }

}



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8088707c-ac55-4c74-bc2d-ee7395cb52e5%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

nani.thrinath.info

unread,
Jan 14, 2014, 1:25:04 AM1/14/14
to seleniu...@googlegroups.com

Use Follows

FileOutputStream fo = new FileOutputStream("D:\\eclipse\\workspace\\Selenium_Project\\Results\\Results.xls");
WritableWorkbook wb=Workbook.createWorkbook(fo);
WritableSheet ws=wb.createSheet("Results", 0);
Label un=newLabel(0, 0, "UserName");
Label pw=newLabel(1, 0, "Password");
Label rslt=newLabel(2, 0, "Result");
ws.addCell(un);
ws.addCell(pw);
ws.addCell(rslt);
wb.write();
wb.close();


Regards,
Thrinath



For more options, visit https://groups.google.com/groups/opt_out.



--
Thrinath

Panikera Raj

unread,
Jan 14, 2014, 7:57:29 AM1/14/14
to seleniu...@googlegroups.com
Hi Shaik,
 
Can we update excel sheet which is already created(like uppending text to the excel )
 
Regards,
Panikera

nani.thrinath.info

unread,
Jan 14, 2014, 8:35:56 AM1/14/14
to seleniu...@googlegroups.com
yes, you can update!



For more options, visit https://groups.google.com/groups/opt_out.



--
Thrinath

Panikera Raj

unread,
Jan 15, 2014, 6:19:52 AM1/15/14
to seleniu...@googlegroups.com
Hi Nani,
Can you provide sample snippet for to Update excel file
 
Regards,
Panikera

Krishnan Mahadevan

unread,
Jan 15, 2014, 6:21:32 AM1/15/14
to Selenium Users
Guys!!

This is a Selenium/WebDriver forum. Please help keep this forum relevant by posting queries related to it.

You might as well take this offline amongst yourselves !

Thanks in advance for your understanding

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


nani.thrinath.info

unread,
Jan 15, 2014, 6:23:40 AM1/15/14
to seleniu...@googlegroups.com
FileOutputStream fo = new FileOutputStream("D:\\eclipse\\workspace\\Selenium_Project\\Results\\Results.xls");
WritableWorkbook wb=Workbook.createWorkbook(fo);
WritableSheet ws=wb.createSheet("Results", 0);
Label un=newLabel(0, 0, "UserName");
Label pw=newLabel(1, 0, "Password");
Label rslt=newLabel(2, 0, "Result");
ws.addCell(un);
ws.addCell(pw);
ws.addCell(rslt);
wb.write();
wb.close();

Regards,
Thrinath


For more options, visit https://groups.google.com/groups/opt_out.



--
Thrinath

Ashok kumar

unread,
Jan 16, 2014, 6:45:22 AM1/16/14
to seleniu...@googlegroups.com
Hi,

If you would prefer working with POI(which is widely used now) , download the Data Driven Framework from below link to write data to Excel. Using this you can write data in an existing excel file.

Download From: http://automationtestingutilities.blogspot.in/

For writing data, you would use the below code snippet.

String excelResource = "ExcelTestData.xlsx"; 
ExcelRuntimeOutput writer = new ExcelRuntimeOutput( 
excelResource); 
writer.backupExcel(); 
writer.setValueAt("SheetName", 0, 0, "MyDataAtFirstRowFirstColumn"); 
writer.setValueAt("SheetName", 0, 1, "MyDataAtFirstRowSecondColumn"); 
writer.generateExcel();

The Sample Project has the code that explains how to write to excel.

Regards 
Ashok
Reply all
Reply to author
Forward
0 new messages