This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tesss; | |
import java.io.File; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.OutputType; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.chrome.ChromeOptions; | |
import net.sourceforge.tess4j.Tesseract; | |
import net.sourceforge.tess4j.TesseractException; | |
/*<dependency> | |
<groupId>net.sourceforge.tess4j</groupId> | |
<artifactId>tess4j</artifactId> | |
<version>4.3.1</version> | |
</dependency>*/ | |
public class Tesss { | |
public static void main(String[] args) throws TesseractException, InterruptedException { | |
/* | |
* File src = new File("C:\\OCR\\tess.png"); Tesseract tesseract = new | |
* Tesseract(); String text = tesseract.doOCR(src); | |
* System.out.println(text); | |
*/ | |
System.setProperty("webdriver.chrome.driver", | |
"C:\\Users\\Mutturaj\\muttu11\\muttu11\\Drivers\\chromedriver.exe"); | |
ChromeOptions ops = new ChromeOptions(); | |
ops.addArguments("--disable-notifications"); | |
WebDriver driver = new ChromeDriver(ops); | |
driver.manage().deleteAllCookies(); | |
driver.manage().window().maximize(); | |
driver.get("https://www.irctc.co.in/nget/train-search"); | |
driver.findElement(By.id("loginText")).click(); | |
Thread.sleep(5000); | |
File file = driver.findElement(By.id("captchaImg")).getScreenshotAs(OutputType.FILE); | |
// C:\\OCR\\tess.png" | |
String str = new Tesseract().doOCR(file); | |
String data="C:\\Users\\diya-mutturajh\\test\\tessdata"; | |
//Set path for yout tessdata folder | |
tesseract.setDatapath(data); | |
System.out.println(str); | |
str = str.split("below")[1]; | |
System.out.println(str); | |
driver.quit(); | |
} | |
} |