What is the best way to take a screenshot of a web page? At the moment I just start a selenium instance of firefox and using winapi bring it to the front and make a screenshot. I ask a similar question already.
There are two points:
- Slowness.
- If any window currently gets higher than our web browser's window, this window will imprint in our screenshot.
Is there any method to take screenshot more 'programming'?
Here is some code I use now:
class FirefoxDriverEx : FirefoxDriver
{
public Process GetFirefoxProcess()
{
var fi = typeof(FirefoxBinary).GetField("process", BindingFlags.NonPublic | BindingFlags.Instance);
return fi.GetValue(this.Binary) as Process;
}
}
Here is the code illustrating the process of taking screenshot itself:
using (FirefoxDriverEx driver = new FirefoxDriverEx())
{
driver.Navigate().GoToUrl(url);
var process = driver.GetFirefoxProcess();
if (process != null)
{
var screenCapture = new ScreenCapture();
Win.SetForegroundWindow(process.MainWindowHandle.ToInt32());
}
}
Right now, I'm thinking about some manager that will control a queue of windows to take the screenshots from.
Question edit#1:
I'm not looking for a solution to just get screenshot 'in memory' and return it back to HTTP stream. So anyways to save the screenshot and save it to file and then get it from there is very ambiguous for that purpose.
Question edit #2.
I forgot to mention. The needed screenshot should be made as it is seen by the user. So, the screenshot should have browser window and a site inside of web browser window's bounds. I can't find any way to change the mode of taking a screenshot in WebDriver of selenium. WebDriver just take a screenshot of a page without any browser window.