Selenium webdriver 在selenium中使用ApachePOI在excel中设置单元格值时,我遇到了空点异常

Selenium webdriver 在selenium中使用ApachePOI在excel中设置单元格值时,我遇到了空点异常,selenium-webdriver,apache-poi,Selenium Webdriver,Apache Poi,这是使用ApachePOI的selenium代码,我从excel中读取一个文件值并打开一个链接,同时在excel文件中写入一个字符串值,这给了我空点异常。你能告诉我怎么了吗 在最后一行,我得到了错误,这些行是:- sheet1.getRow(i).getCell(2).setCellValue(linkLocatin); File src = new File ("C:\\Sandeep\\Selenium\\automationproject1\\Testdata.xlsx"); 我的所有

这是使用ApachePOI的selenium代码,我从excel中读取一个文件值并打开一个链接,同时在excel文件中写入一个字符串值,这给了我空点异常。你能告诉我怎么了吗

在最后一行,我得到了错误,这些行是:-

sheet1.getRow(i).getCell(2).setCellValue(linkLocatin);

File src = new File ("C:\\Sandeep\\Selenium\\automationproject1\\Testdata.xlsx");
我的所有代码:-

        FileInputStream fis = new FileInputStream(src);

        XSSFWorkbook wb =new XSSFWorkbook (fis);

        XSSFSheet sheet1 =wb.getSheetAt(0);

        int rowcount= sheet1.getLastRowNum();
        XSSFCell cel;

         //System.out.println ("Test data is " + data0);
        System.out.println ("rowncount is = "+ rowcount);

     for (int i=1; i<= rowcount;i++)
        {

        //Set browser profile and then get link from excel
        FirefoxProfile prof = new FirefoxProfile();

         prof.setPreference("media.windows-media-foundation.enabled", false);
         prof.setPreference("media.directshow.enabled", false);
         prof.setAcceptUntrustedCertificates(true);
         prof.setPreference("browser.download.dir","C:\\Sandeep\\Selenium\\automationproject1\\Download1");
         prof.setPreference("browser.helperApps.alwaysAsk.force", false);
         prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "audio/x-mpeg-3"); 
         prof.setPreference("browser.download.folderList", 2);
         prof.setPreference("browser.download.manager.showWhenStarting",false);

        WebDriver driver = new FirefoxDriver(prof);

        String data0 = sheet1.getRow(i).getCell(1).getStringCellValue(); 
        System.out.println(data0);

        // open the link in browser         
        driver.get(data0);                  
        WebElement link = driver.findElement(By.linkText("Download the recording"));
        String linkLocatin = link.getAttribute("href");
        sheet1.getRow(i).getCell(2).setCellValue(linkLocatin);

在excel中设置字符串值时,显示空点异常..W

行或单元格是否为空?如果检查是否存在,并在行和单元格访问周围创建(如果不存在)代码,会发生什么情况?请确保String linkLocatin未打印空值。请阅读指南,尤其是最小、完整和可验证示例MCVE的部分。这将帮助你自己解决问题。如果您这样做了,但仍然陷入困境,您可以回来发布您的MCVE、您尝试了什么以及结果如何,以便我们能够更好地帮助您。sheet1.getRowi.getCell2.setCellValuelinkLocatin;仅当excel单元格以前包含某些数据时才更新该单元格。因此,解决方法是使用伪值填充单元格,并让此方法更新该值。