Selenium get_screenshot_as_file vs get_screenshot_as_base64?

与世无争的帅哥 提交于 2019-12-13 05:05:23

问题


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

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

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?


回答1:


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.

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.

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).

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.



来源:https://stackoverflow.com/questions/25565737/selenium-get-screenshot-as-file-vs-get-screenshot-as-base64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!