使用Java的Selenium Webdrier:从Excel读取时出现异常

时间:2016-09-06 11:02:54

标签: java selenium-webdriver

我正在使用SeleniumWebDriver使用Java来自动化其中一个门户应用程序。作为其中的一部分,我想从Excel中读取用户名和密码,并在下面的代码中编写。但是看到Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/drawingml/x2006/main/ThemeDocument下面是代码

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.util.Random;

    public class BankingFaceLift {
        static WebDriver  driver = null;


        public static void main(String[]args){

            driver = new FirefoxDriver();
            driver.get("https://obsit.enbduat.com/obweb/common/login.jsf?faces-redirect=true");
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

            try
            {    
                File file = new File("TestData.xlsx");
                FileInputStream iFile = new FileInputStream(file);

                XSSFWorkbook wb = new XSSFWorkbook(iFile);
                XSSFSheet sheet = wb.getSheet("Sheet1");

                int rowCount = sheet.getLastRowNum();
                System.out.println("the no of rows are : " + rowCount);
                for (int row=1; row<=rowCount; row++)
                {

                    String Username = sheet.getRow(row).getCell(0).getStringCellValue();
                    String Password = sheet.getRow(row).getCell(1).getStringCellValue();
                    driver.findElement(By.id("username")).sendKeys(Username);
                    driver.findElement(By.id("j_idt49")).sendKeys(Password);
                    driver.findElement(By.id("submit")).click();

我已导入poi-xxx.jarpoi-ooxml.jar1

请建议谢谢!

1 个答案:

答案 0 :(得分:2)

您还需要导入poi-ooxml-schemas jar。您可以从here

下载jar