- sreekumarActive particpant
- Posts : 16
Join date : 2011-12-27
Age : 39
Location : Hyderabad
Need Selenium Webdriver + Excel sheet examples
Tue Mar 06, 2012 9:06 pm
Hi All
Please give me some examples for read/write operations from excel sheet using selenium webdriver.
I tried a few examples but getting ArrayIndexOutofBound exception getting
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class TestData{
WebDriver driver = new ChromeDriver();
public void Login() throws InterruptedException, BiffException, IOException
{
FileInputStream fi=new FileInputStream("D:\\sreeworkspace\\sree.xls");
Workbook workbook = Workbook.getWorkbook(fi);
Sheet sheet = workbook.getSheet("Login");
String s=sheet.getCell(2,2).getContents();
System.out.println(s);
driver.findElement(By.id("gbqfq")).sendKeys(s);
driver.findElement(By.name("btnK")).click();
}
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
System.setProperty("webdriver.chrome.driver", "D:/sreekumar/Tutorial/Selenium/chromedriver_win_18.0.995.0/chromedriver.exe");
//Pausing here seems to make it work better, so...
TestData login = new TestData();
login.driver.get("https://www.google.com");
login.Login();
}
}
Please give me some examples for read/write operations from excel sheet using selenium webdriver.
I tried a few examples but getting ArrayIndexOutofBound exception getting
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class TestData{
WebDriver driver = new ChromeDriver();
public void Login() throws InterruptedException, BiffException, IOException
{
FileInputStream fi=new FileInputStream("D:\\sreeworkspace\\sree.xls");
Workbook workbook = Workbook.getWorkbook(fi);
Sheet sheet = workbook.getSheet("Login");
String s=sheet.getCell(2,2).getContents();
System.out.println(s);
driver.findElement(By.id("gbqfq")).sendKeys(s);
driver.findElement(By.name("btnK")).click();
}
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
System.setProperty("webdriver.chrome.driver", "D:/sreekumar/Tutorial/Selenium/chromedriver_win_18.0.995.0/chromedriver.exe");
//Pausing here seems to make it work better, so...
TestData login = new TestData();
login.driver.get("https://www.google.com");
login.Login();
}
}
- ArahantActive particpant
- Posts : 23
Join date : 2012-02-29
Re: Need Selenium Webdriver + Excel sheet examples
Wed Mar 07, 2012 12:32 pm
Hi ,
I gone through your code.you are trying to read excel spread sheet.For this try to use below code might be helpful for you.
@DataProvider (name = "DP1")
public Object[][] readdata() throws Exception{
Object[][] retObjArr=gettableArry("test\\Resources\\Data\\data1.xls","DataPool","ImdbTestData1");
return(retObjArr);
}
@Test (dataProvider = "DP1")
public void testdataprovider(String Type,String Os,String Version,String Language) throws Exception{
(Here number of string and name should be same with your excel sheet column)
System.out.println("Type is ===>" Type);
System.out.println("os is ===>" Os);
System.out.println("version is ===>" Version);
System.out.println("language is ===>" Language);
}
private Object[][] gettableArry(String xslsheet, String sheetname, String tablename) throws Exception {
String[][] tabArray=null;
Workbook wb = Workbook.getWorkbook(new File(xslsheet));
Sheet st = wb.getSheet(sheetname);
int startRow,startCol, endRow, endCol,ci,cj;
Cell tableStart=st.findCell(tablename);
startRow=tableStart.getRow();
System.out.println("Initiated rows to sheet ======>" startRow);
startCol=tableStart.getColumn();
Cell tableEnd = st.findCell(tablename, startCol 1,startRow 1, 100, 64000, false);
endRow=tableEnd.getRow();
endCol=tableEnd.getColumn();
tabArray=new String[endRow-startRow-1][endCol-startCol-1];
ci=0;
for (int i=startRow 1;i
I gone through your code.you are trying to read excel spread sheet.For this try to use below code might be helpful for you.
@DataProvider (name = "DP1")
public Object[][] readdata() throws Exception{
Object[][] retObjArr=gettableArry("test\\Resources\\Data\\data1.xls","DataPool","ImdbTestData1");
return(retObjArr);
}
@Test (dataProvider = "DP1")
public void testdataprovider(String Type,String Os,String Version,String Language) throws Exception{
(Here number of string and name should be same with your excel sheet column)
System.out.println("Type is ===>" Type);
System.out.println("os is ===>" Os);
System.out.println("version is ===>" Version);
System.out.println("language is ===>" Language);
}
private Object[][] gettableArry(String xslsheet, String sheetname, String tablename) throws Exception {
String[][] tabArray=null;
Workbook wb = Workbook.getWorkbook(new File(xslsheet));
Sheet st = wb.getSheet(sheetname);
int startRow,startCol, endRow, endCol,ci,cj;
Cell tableStart=st.findCell(tablename);
startRow=tableStart.getRow();
System.out.println("Initiated rows to sheet ======>" startRow);
startCol=tableStart.getColumn();
Cell tableEnd = st.findCell(tablename, startCol 1,startRow 1, 100, 64000, false);
endRow=tableEnd.getRow();
endCol=tableEnd.getColumn();
tabArray=new String[endRow-startRow-1][endCol-startCol-1];
ci=0;
for (int i=startRow 1;i
- sreekumarActive particpant
- Posts : 16
Join date : 2011-12-27
Age : 39
Location : Hyderabad
Re: Need Selenium Webdriver + Excel sheet examples
Thu Mar 08, 2012 8:16 pm
Thank you so much , the above example works fine.....
- ashish_techieAmateur
- Posts : 73
Join date : 2011-08-09
Re: Need Selenium Webdriver + Excel sheet examples
Mon May 14, 2012 11:33 pm
Use the POI API.
Regards
Ashish
For selenium videos visit:
http://qtpselenium.com/selenium-tutorial
Regards
Ashish
For selenium videos visit:
http://qtpselenium.com/selenium-tutorial
Permissions in this forum:
You cannot reply to topics in this forum