硒 get_screenshot_as_file 与 get_screenshot_as_base64? [英] Selenium get_screenshot_as_file vs get_screenshot_as_base64?

查看:63
本文介绍了硒 get_screenshot_as_file 与 get_screenshot_as_base64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一个相对于另一个的优点/缺点是什么?

I'm wondering what the advantages/disadvantages of one over the other are?

我在无头远程实例上运行 Selenium Server,Xvfb 作为显示器.

I'm running against Selenium Server on a headless remote instance with Xvfb acting as the display.

两种方法都可以正常工作,并且生成的屏幕截图文件(如果我转换 base64 并将其另存为图像文件)具有相同的文件大小和外观.

Both methods work fine and the resulting screen capture file (if I convert the base64 one and save it as an image file) are identical file size and look identical.

那么为什么我要使用/不使用另一个?

So why would I want to use/not use one over the other?

推荐答案

使用 get_screenshot_as_file 将屏幕截图保存为二进制文件,而使用 get_screenshot_as_base64 这将返回该屏幕截图的 base64 编码版本.

With the get_screenshot_as_file, the screenshot get saves into a binary file, while with get_screenshot_as_base64 this will return you base64 encoded version of that screenshot.

那么,为什么会有人使用 base64 版本?base64 背后的整个想法是它允许您创建二进制数据的 ASCII 表示,这将增加数据大小,但也允许您实际使用它.例如,如果您尝试将二进制数据流发送到套接字,而不对其进行编码,那么除非服务器准备好处理二进制数据,否则结果很难预测.

So, why would anyone use the base64 version? The whole idea behind base64 is that it allows you to create ASCII representation of binary data, which will increase the data size but will also allow you to actually work with it. For example if you've tried to send over a stream of binary data to a socket, without encoding it then unless server was prepared to handle binary data, the result is hard to predict.

由于传输的数据可能格式不正确,因此请提前切断传输并导致许多其他几乎无法预测的结果.例如,如果您要运行一个非常简单的套接字服务器,它将接收到的所有内容都打印到 std::out,那么接收二进制文件很可能会损坏您的控制台终端(您可以在您自己的 Linux 机器上尝试它).

As a result of that the data transferred may be malformed, cut the transfer early and cause many other results that are almost impossible to predict. For example if you were to run a very simple socket server that just prints out everything as it receives to std::out, receiving a binary file would most likely corrupt your console terminal (you can try it on your very own Linux box).

当然,如果服务器被设计为接收和处理二进制数据,那么这将不是问题,但大多数情况下,服务器端会将用户输入解释为字符串,这使得使用 base64 成为明智的选择.

Of course if the server is designed to receive and handle binary data then this will not be an issue, but most often the server-end will interpret user input as string which makes using base64 a wise choice.

这篇关于硒 get_screenshot_as_file 与 get_screenshot_as_base64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆