【问题标题】:Cannot decode BASE64 to Image file in Selenium 2无法将 BASE64 解码为 Selenium 2 中的图像文件
【发布时间】:2012-03-08 18:54:50
【问题描述】:

我有一个来自屏幕截图的 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)参数。这很奇怪,因为当您看到选项时,有一个 write(Byte[] b)。

你能帮我解开这个谜吗? 谢谢

【问题讨论】:

    标签: java base64 screenshot selenium-webdriver decode


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 2018-07-13
        • 2012-10-05
        • 2017-01-09
        • 1970-01-01
        • 2016-04-04
        • 2018-09-05
        相关资源
        最近更新 更多