我正在尝试捕获图像的文本,但是我得到了空指针异常,这是我正在使用的代码
我检查了几个链接,我认为问题是Mac系统还是32/64位,当前我正在使用64位macbook。有什么工作可以解决这种情况
File src =
driver.findElement(By.id("CaptchaImage")).getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir")+"/screenshots/captcha.png";
FileHandler.copy(src, new File(path));
String path1 = System.getProperty("user.dir")+"/screenshots/captcha.png";
ITesseract image = new Tesseract();
String imageText = image.doOCR(new File(path1));
System.out.println(imageText);
imageText = imageText.replaceAll("[^a-zA-Z]", "");
System.out.println(imageText);
driver.findElement(By.xpath("//input[@name='CaptchaInputText']")).sendKeys(imageText);
这是我得到的错误:
8:57:42.210 [main] ERROR net.sourceforge.tess4j.Tesseract - null
java.lang.NullPointerException: null
at net.sourceforge.tess4j.Tesseract.dispose(Tesseract.java:819)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:239)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:194)
at com.booking.sample.come.nooking.sample.appointment.bookApointment(appointment.java:55)
at com.booking.sample.come.nooking.sample.appointment.main(appointment.java:32)