繁体   English   中英

在Selenium 2中无法将BASE64解码为Image文件

[英]Cannot decode BASE64 to Image file in Selenium 2

我有截图捕获的BASE64图像,我想在image.png文件中转换,但是有一些我无法理解的编译错误。

    Object ss = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
    Base64 decoder = new Base64();
    Byte[] imgBytes = (Byte[]) decoder.decode(ss);
    FileOutputStream osf = new FileOutputStream(new File("./screenshots/"+ System.getProperty("logfilename") + ".png"));        
    osf.write(imgBytes);
    osf.flush();

上面代码中的编译错误在osf.write(imgBytes)行中,它告诉我write()方法不接受Byte []对象,因为它告诉我该方法只接受write(int i)args。 这很奇怪,因为当你看到选项时会有一个写(Byte [] b)。

你能帮我解决一下这个谜语吗? 谢谢

如果您只想将其另存为文件,则应使用OutputFile.FILE枚举。 这基本上包含了你的解码。

write func采用原始字节而不是包装类,即byte []而不是Byte []。 所以编译错误..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM