Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99418

Selenium VB.Net 2019 Save canvas image

$
0
0

Using the Code given at this link by mehmet mecek

I am attempting to Save the Image of Tag using Selenium VB.net 2019. My code for this action is

Dim ele = driver.FindElementByClassName("canvasWrapper")
Dim base64string = Trycast(driver.ExecuteScript("
                    var c = document.createElement('canvas');
                    var ctx = c.getContext('2d');
                    var img = document.getElementById('page1');
                    c.height=img.naturalHeight;
                    c.width=img.naturalWidth;
                    ctx.drawImage(img, 0, 0,img.naturalWidth, img.naturalHeight);
                    var base64String = c.toDataURL();
                    return base64String;
                    "), String)
MsgBox(base64string.ToString())

Dim base64 = base64string.Split(",").Last()

Dim stream = New MemoryStream(Convert.FromBase64String(base64))
Dim bmCaptured As Bitmap = New Bitmap(stream)
bmCaptured.Save(Path + "\" + pageNum.ToString + ".jpg", Imaging.ImageFormat.Jpeg)

I am getting error `The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. I have tried With and Without Trycast but am not able to save the canvas but some errors keep cropping up.


Viewing all articles
Browse latest Browse all 99418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>