Selenium VB.Net 2019保存画布图像

问题描述 投票:0回答:1

[Using the Code given at this link by mehmet mecek

我正在尝试使用Selenium VB.net 2019保存标签图像。此操作的代码是

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)

我收到错误信息`输入不是有效的Base-64字符串,因为它包含非Base 64字符,两个以上的填充字符或填充字符中的非法字符。我尝试了“有和没有Trycast”,但无法保存画布,但是有些错误不断出现。

vb.net selenium canvas save
1个回答
0
投票
[VB.Net代码-知道了...但是尝试其他解决方法
© www.soinside.com 2019 - 2024. All rights reserved.