使用 selenium webdriver,我将测试html2canvas JS 脚本以直接在浏览器上拍摄网页或其部分的“屏幕截图”。我编写了这个 C# 代码来测试它,但 obj 始终为空。
C# 代码供参考
IWebDriver Driver = new FirefoxDriver();
Driver.Navigate().GoToUrl("http://www.monsite.com");
string scriptJS = File.ReadAllText("html2canvas.js");
scriptJS += @"
html2canvas(document.body, {
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png");
return img;
}
});";
IJavaScriptExecutor executorJS = Driver as IJavaScriptExecutor;
var obj = executorJS.ExecuteScript(scriptJS);