我无法将excel数据提取到selenium代码在ubuntu o / s

时间:2014-03-19 11:27:20

标签: excel selenium

public class ReadAndWrite {
public static void main(String[] args) throws InterruptedException, BiffException, IOException 
{
    System.out.println("hello");
    ReadAndWrite.login();
}
public static void login() throws BiffException, IOException, InterruptedException{
    WebDriver driver=new FirefoxDriver();
    driver.get("URL");
    System.out.println("hello");

    FileInputStream fi = new FileInputStream("/home/sagarpatra/Desktop/Xpath.ods");
    System.out.println("hiiiiiii");
    Workbook w = Workbook.getWorkbook(fi);
    Sheet sh = w.getSheet(1); 
    //or w.getSheet(Sheetnumber)
    //String variable1 = s.getCell(column, row).getContents();

    for(int row=1; row <=sh.getRows();row++)
    {
    String username = sh.getCell(0, row).getContents();
    System.out.println("Username "+username);
    driver.get("URL");
    driver.findElement(By.name("Email")).sendKeys(username);
    String password= sh.getCell(1, row).getContents();
    System.out.println("Password "+password);
    driver.findElement(By.name("Passwd")).sendKeys(password);
    Thread.sleep(10000);
    driver.findElement(By.name("Login")).click();
     System.out.println("Waiting for page to load fully...");
    Thread.sleep(30000);
    }
    driver.quit();
    }

}

我不知道我的代码有什么问题,或者如何修复它。它输出以下错误:

Exception in thread "main" jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at test.ReadTest.main(ReadTest.java:19)

1 个答案:

答案 0 :(得分:0)

我会尝试使用Apache MetaModel代替。我使用JXL比运气好。从.XLSX文件中读取的Here is a example project I wrote。我使用此库从MSW上生成的.XLS文件在Linux Jenkins服务器上运行测试。

另外,应该注意的是,这个库也非常适合用于使用JDBC查询数据库的参数化DataProvider。

使用JXL,您可以将自己限制为一种数据类型,.XLS或.CSV。我相信MetaModel实际上是在引擎盖下使用JXL并将其包装起来以便于使用。因此,它也会以相同的方式支持OpenOffice文档,并且遇到相同的文件兼容性问题。