We have a system where we generate .xlsx files and provide download links for them. Obviously, clicking on those links to download a file is not feasible as it would either pop up a native dialogue box that I can’t control, or download directly to a location that is dependent on platform (win, linux, mac) and browser (we might test on different browsers).
My solution is to use ‘Execute Javascript’ to do an XMLHttpRequest call to GET the file using the href of the tag and then return the data to RF… The JS I have so far to do this is
${raw_content}= Execute Javascript let r=new XMLHttpRequest();r.open(“GET”,“${file_url}”,false);r.overrideMimeType(“text/plain; charset=x-user-defined”);r.send(null);return r.responseText;
In theory this should return the binary data for the .xlsx file and it seems to do that. The difficulty is that the resultant string ${raw_content} is a standard Python string (Unicode) and cannot figure out how to decode this back into the correct binary representation to write it to disk so I can open it as an Excel spreadsheet and analyse it.
I’ve tried everything I know… convert to bytes/bytearray… Base64 encode in the browser using JS btoa(…) then decode in python at the other end etc etc etc but I can’t seem to recreate the original binary representation.
Thanks in advance for any help…