0
I’m trying to store an image with JS and is giving an error in return.
Error message:
VM85:8 Uncaught Syntaxerror: Illegal Return statement
I’m doing it for Selenium with C, follow my code:
IJavaScriptExecutor Lobj_JS = (IJavaScriptExecutor)Navegador;
var Lstr_TagImgBase64 = Lobj_JS.ExecuteScript($@"
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = document.evaluate('//html/body/div/div[@id='content']/form/div/div/span/div/div/img', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
canvas.height=img.height;
canvas.width=img.width;
ctx.drawImage(img, 0, 0,img.width, img.height);
var base64String = canvas.toDataURL();
return base64String;") as string;
I cannot handle this error, when running in Chrome I obviously replace the single quotes, staying in the console this way:
[@id="content"]
Now it makes sense, I don’t have much experience with JS now cleared the mind.
– Pedro Duca