【发布时间】:2018-10-05 12:40:07
【问题描述】:
我已经写了这段代码:
import java.awt.Image;
import java.awt.image.RenderedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
// class and method declaration omitted
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//store screenshot at a specidfied location
File targetFile=new File("C:\\Users\\Srujan\\eclipse-workspace\\Batch98Appium\\images\\kiran.png");
FileUtils.copyFile(scrFile,targetFile );
System.out.println(targetFile.toString());
// URL url1 = new URL(targetFile.toString());
Image image = ImageIO.read(targetFile);
// we are asking it to recognize the characers present in the image and we are asking to it to read the contnet and to store the content in a variable
String s = new OCR().recognizeCharacters((RenderedImage) image);
//below cmd is simply printing the information
System.out.println("Text From Image : \n"+ s);
if (s.contains("Monitored switch is on")) {
System.out.println("toastr verified successfully");
} else {
System.out.println("toastr not verified successfully");
}
我添加了 jars 作为 Maven 依赖项:
Java OCR API 15.3.0.1
java-client 6.1.0
出现如下编译错误:
String s = new OCR().recognizeCharacters((RenderedImage) image);
OCR().Recog...OCR 无法解析为类型。
【问题讨论】:
-
你们班的
import声明是什么? -
导入 java.awt.Image;导入 java.awt.image.RenderedImage;导入java.io.File;导入 java.net.MalformedURLException;导入 java.net.URL;导入 javax.imageio.ImageIO;导入 org.apache.commons.io.FileUtils;导入 org.openqa.selenium.OutputType;导入 org.openqa.selenium.TakesScreenshot;导入 org.openqa.selenium.WebElement;导入 org.openqa.selenium.remote.DesiredCapabilities;导入 io.appium.java_client.android.AndroidDriver;导入 io.appium.java_client.remote.MobileCapabilityType;
-
新 ORC() 周围可能需要括号,例如。字符串 s = (new OCR()).recog
-
您的导入语句都没有导入
OCR类。 -
从 OP 的评论中添加了导入。格式化代码
标签: java selenium selenium-webdriver appium-android