空指针尝试获取存储在变量中的excel值时发生异常

时间:2018-07-18 10:55:49

标签: selenium-webdriver

public class Readingexcelasinput {
    WebDriver Driver1;
    public void readExcel() throws BiffException, IOException {
    String FilePath = "D:\\eclipse-jee-photon-R-win32-x86_64\\eclipse\\WebsiteTest\\Lib\\ChromeLib\\chromedriver_win32\\TestData1.xls";
    FileInputStream fs = new FileInputStream(FilePath);
    Workbook wb = Workbook.getWorkbook(fs);
    Sheet sh1 = wb.getSheet("Sheet1");
    int totalNoOfRows = sh1.getRows();
    int totalNoOfCols = sh1.getColumns();
    for (int row = 1; row < totalNoOfRows; row++) 
    {
        for (int col = 1; col < totalNoOfCols; col++) 
        {
            String a = sh1.getCell(col, row).getContents();
            //cell.setCellType(Cell.CELL_TYPE_STRING);
            System.out.print(a);
            Driver1.findElement(By.name("first_name")).sendKeys("a");---Null point Exception
            }
        }
    }
    public static void openbrowser()
    {
        System.setProperty("webdriver.chrome.driver","D:/eclipse-jee-photon-R-win32-x86_64/eclipse/WebsiteTest/Lib/ChromeLib/chromedriver_win32/chromedriver.exe");
        WebDriver Driver1 = new ChromeDriver();
        Driver1.manage().deleteAllCookies();
        Driver1.manage().window().maximize();
        Driver1.get("http://adjiva.com/qa-test/");
    }
    public static void main(String args[]) throws BiffException, IOException {
        Readingexcelasinput rs = new Readingexcelasinput();
        rs.openbrowser();
        rs.readExcel();
    }
}

运行上述代码后,出现以下异常,并且无法从excel文件中输入数据。

  

线程“主”中的异常java.lang.NullPointerException         在co.uploadimagefb.Readingexcelasinput.readExcel(Readingexcelasinput.java:45)         在       co.uploadimagefb.Readingexcelasinput.main(Readingexcelasinput.java:64)

0 个答案:

没有答案