我正在使用以下代码从WinAppDriver会话中捕获屏幕截图,然后将其传递给Tesseract Pix类以进行OCR,以浏览WinAppDriver会话(Win32应用程序)无法识别的表中的链接。笔记会话是使用WinAppDriver的$value['horario_abertura']
WindowsDriver<WindowsElement>
如评论中所述,我可以在本地保存文件,然后访问它。但是,我希望通过using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium;
using System.Configuration;
using Tesseract;
[TestMethod]
public void ImageTest()
{
String ImagePath = @"c:\temp\Image.png";
var screen = session.GetScreenshot();
screen.SaveAsFile(ImagePath, ScreenshotImageFormat.Png);
Pix ImagefromFile = Pix.LoadFromFile(ImagePath); // Works
var screenmemory = session.GetScreenshot().AsByteArray;
Pix ImagefromMemory = Pix.LoadTiffFromMemory(screenmemory); // Fails with "IOExeception: Failed to load image from memory
}
来实现。测试失败,出现异常LoadTiffFromMemory
答案 0 :(得分:0)
该屏幕截图很可能不是TIFF格式的。你可以试试吗?
Pix ImagefromMemory = Pix.LoadFromMemory(screenmemory);
或
MemoryStream memStream = new MemoryStream();
screen.Save(memStream, ImageFormat.Tiff);
Pix ImagefromMemory = Pix.LoadTiffFromMemory(memStream.ToArray());