i\'m trying to save an image from a website using selenium server & python client. i know the image\'s URL, but i can\'t find the code to save it, either when it\'s the the
I found code that puts an image in to a canvas, then converts it to data - which could then be base64 encoded for example. My thought was to call this using the eval command in selenium, however in my testing the toDataURL is throwing a security error 1000. Seems like it is so close to a solution if not for that error.
var data, canvas, ctx;
var img = new Image();
img = document.getElementById("yourimageID");
canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0); // everything works up to here
data = canvas.toDataURL(); // this fails ***
var base64Img = data.replace(/^data:image\/(png|jpg);base64,/, "");
Doing some research I found references that it is not allowed to use toDataURL when the image is from a different domain. However, I even tried this code by saving the page, stripping everything out except the image itself and this script.
For example (index.html) :
The img.jpg and index.html are stored locally, opening the page in firefox locally, still get a security error 1000!