Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
sreekumar
Active particpant
Active particpant
Posts : 16
Join date : 2011-12-27
Age : 39
Location : Hyderabad

Need Selenium Webdriver + Excel sheet examples Empty 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();
}
}
avatar
Arahant
Active particpant
Active particpant
Posts : 23
Join date : 2012-02-29

Need Selenium Webdriver + Excel sheet examples Empty 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
avatar
sreekumar
Active particpant
Active particpant
Posts : 16
Join date : 2011-12-27
Age : 39
Location : Hyderabad

Need Selenium Webdriver + Excel sheet examples Empty Re: Need Selenium Webdriver + Excel sheet examples

Thu Mar 08, 2012 8:16 pm
Thank you so much , the above example works fine.....
avatar
ashish_techie
Amateur
Amateur
Posts : 73
Join date : 2011-08-09

Need Selenium Webdriver + Excel sheet examples Empty 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
Sponsored content

Need Selenium Webdriver + Excel sheet examples Empty Re: Need Selenium Webdriver + Excel sheet examples

Back to top
Permissions in this forum:
You cannot reply to topics in this forum