I'm trying to download a blob PDF file with Selenium. The source page doesn't contain a link to this PDF, the link is created "on the fly", so I make some manipulations on the site, get "blob:https://.." link and run the JS below to get this file:
function blobToString(b) {
var u, x;
u = URL.createObjectURL(b);
x = new XMLHttpRequest();
x.open('GET', u, false);
x.send();
URL.revokeObjectURL(u);
return x.responseText;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', 'blob:https://...........', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var myBlob = this.response;
document.querySelector("body").setAttribute("test",blobToString(myBlob));
}
};
xhr.send();
So, for now I'm able to get this blob PDF to Selenium by saving it's content to some element's attribute and getting it to the Selenium after that.
The problem is that PDF doesn't open as a normal file, some of it's content is coded with strange symbols:
Downloaded with Selenium: �0 ��W�Ǻ�M�D�J��B�B� Q��P �oﵜ��w�,��� Y�4���E\4~�310�4���bk� �� ɔ�4}p� �\uq���zwcN��i��i��c�V���տ � �
Downloaded manually: Â0^T<85>áWùǺ¤MÒDçJÅÅBáBç^NQ<94>¦P^U±oïµ<9c>åÀwà,ô<94>ò¥¹^\Y¨4¡òÆE\4~Ï310«4<82>ÝØbk¥^CÁÔ^QÉ<94>ç4}pÖ^D<8f>\uq£<90>ôzwcNüËiÌ÷iÝÉc³Vô±§Õ¿^_^\³^^×
So I need to perform some kind of encoding/decoding to make it work. Please, help with this.