How to use html2canvas JavaScript with Selenium webdriver in C#
Posted
by
PapyRef
on Stack Overflow
See other posts from Stack Overflow
or by PapyRef
Published on 2013-09-26T06:16:42Z
Indexed on
2013/10/27
9:55 UTC
Read the original article
Hit count: 983
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);
© Stack Overflow or respective owner