I am very new to Selenium RC. Please, help in my question.
I installed jxl.jar file (Java library for Excel) and added it to Eclipse build path.
I created an Excel file as readdata.xls where I entered some columns like username and password and provided some example inputs for those columns. Something like:
UserName Password Akshit Ak12345 Ashwika AS12345I wrote the following code
package seleniumscripts; import java.io.FileInputStream; import jxl.Sheet; import jxl.Workbook; public class Excelreaddata { private static String husername; private static String hpassword; private static String username; private static String password; public static void main(String[] args) throws Exception { FileInputStream fis =new FileInputStream("C:\\Documents and Settings\\Home\\Desktop\\Readdata.xls"); Workbook wb = Workbook .getWorkbook(fis); Sheet s= wb.getSheet(0); Excelreaddata.husername =s.getCell(0,0).getContents(); Excelreaddata.hpassword =s.getCell(0,1).getContents(); System.out.println(Excelreaddata.husername); System.out.println(Excelreaddata.hpassword); Excelreaddata.username =s.getCell(1,0).getContents(); Excelreaddata.password =s.getCell(1,1).getContents(); System.out.println(Excelreaddata.username); System.out.println(Excelreaddata.password); Excelreaddata.username =s.getCell(2,0).getContents(); Excelreaddata.password =s.getCell(2,1).getContents(); System.out.println(Excelreaddata.username); System.out.println(Excelreaddata.password); } }
My question is: when executing the code results are displayed only for Akshit, not for Ashwika. I need both to display.
Result I am getting like this when executing in Eclipse:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:288)
at seleniumscripts.Excelreaddata.main(Excelreaddata.java:38)
UserName
Akshit
Password
Ak12345