-1

I am trying to read the data from excel file with Java and Selenium Webdriver. However, I am keep getting the error

Exception in thread "main" java.io.FileNotFoundException: T:\SeleniuminputFiles\input.xls (The system cannot find the file specified) eventhough the Excel file is located.

Please find attached screenshot for the code and output screen.

Can someone please kindly help me to resolve this issue as i am really stuck at the moment.

Sushant Tavrawala
  • 45
  • 1
  • 2
  • 14
  • 1
    I dont think you are using Selenium Webdriver to perform this operation. You are using the Java Excel API, which does not support XLSX. You might want to check this question https://stackoverflow.com/questions/6383414/how-to-read-excel-file-with-xlsx-extension – Ashish Narmen Sep 07 '17 at 08:06
  • Hello Ashish. thank you very much. – Sushant Tavrawala Sep 07 '17 at 08:08

1 Answers1

2

You have to put double slashes \\ like below :

T:\\SeleniuminputFiles\\input.xls

OR

String a = "T:"+File.separator+"SeleniuminputFiles"+File.separator+"input.xls";

And

Another thing is to make sure that file should be on same place

And

Change your file format from xlsx to xls because The xls format (< Excel 2007) is comprised of binary BIFF data in an OLE container. The xlsx format (>= Excel 2007) is comprised of XML files in a zip container.

The Java Excel API only deals with the first format so it throws an exception when it doesn't encounter an OLE container.

You will need to restrict your input to xls files only or find another tool that handles both formats.

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Hello Shubham, i am getting same error with both try outs.... The output is:: Excel Located Exception in thread "main" java.io.FileNotFoundException: T:\SeleniuminputFiles\input.xls (The system cannot find the file specified) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(Unknown Source) at java.io.FileInputStream.(Unknown Source) at jxl.Workbook.getWorkbook(Workbook.java:213) at jxl.Workbook.getWorkbook(Workbook.java:198) at TestNg.DataDriven.main(DataDriven.java:17) – Sushant Tavrawala Sep 07 '17 at 08:18
  • if i have Text file in the similar place, i can read it with FileReader file = new FileReader ("T:/AutomationLearning/FileRead/Input.txt"); BufferedReader br = new BufferedReader(file); the issue is only with the Excel... – Sushant Tavrawala Sep 07 '17 at 08:20
  • have you tried File.separator – Shubham Jain Sep 07 '17 at 08:21
  • one other thing check your file extention .. is it .xls or .xlsx – Shubham Jain Sep 07 '17 at 08:22
  • I tried file.separator and the file is xlsx but when i try xlsx it throws different exception. With the Extension .xlsx the output is ::: Excel Located Exception in thread "main" jxl.read.biff.BiffException: Unable to recognize OLE stream at jxl.read.biff.CompoundFile.(CompoundFile.java:116) at jxl.read.biff.File.(File.java:127) at jxl.Workbook.getWorkbook(Workbook.java:221) at jxl.Workbook.getWorkbook(Workbook.java:198) at TestNg.DataDriven.main(DataDriven.java:17) – Sushant Tavrawala Sep 07 '17 at 08:24
  • you need to change the file extention also then .. you can't use xls in code and xlsx as real file name – Shubham Jain Sep 07 '17 at 08:25
  • Yes when i tried with .XLSX extension it throws different errors... With the Extension .xlsx the output is ::: Excel Located Exception in thread "main" jxl.read.biff.BiffException: Unable to recognize OLE stream at jxl.read.biff.CompoundFile.(CompoundFile.java:116) at jxl.read.biff.File.(File.java:127) at jxl.Workbook.getWorkbook(Workbook.java:221) at jxl.Workbook.getWorkbook(Workbook.java:198) at TestNg.DataDriven.main(DataDriven.java:17) – Sushant Tavrawala Sep 07 '17 at 08:28
  • Hello Shubham,,, that solved the issue.... thank you very much..... – Sushant Tavrawala Sep 07 '17 at 08:34
  • Hi shubham, i am getting message that, i require at least 15 reputations to cast the vote.... what is an alternative to help you ... – Sushant Tavrawala Sep 07 '17 at 08:39
  • you are welcome.. :) – Sushant Tavrawala Sep 07 '17 at 09:48