2

I am trying to capture the text of an image however I am getting a null pointer exception, here is the code I am using

I have checked a few links and I think the problem is either with the Mac system or with 32/64 bit, currently, I am using a mac book with 64 bit. is there any workaround to overcome this situation

  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);

Here is the error that I am getting:

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)
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
Sanat
  • 267
  • 1
  • 5
  • 16

0 Answers0