How to use html2canvas JavaScript with Selenium webdriver in C#
- by PapyRef
With selenium webdriver, I would test html2canvas JS script to take "screenshots" of webpages or parts of it, directly on the browser.
I have a written this C# code to test it, but obj is always null.
C# Code for reference
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);