'Selenium full webpage screenshot
How to take screenshot of full webpage in selenium with c#. Noksa package doesn't have .ToBitmap() function as suggested in many videos.
Solution 1:[1]
Here is snippet from the docs
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.example.com");
Screenshot screenshot = (driver as ITakesScreenshot).GetScreenshot();
screenshot.SaveAsFile("screenshot.png", ScreenshotImageFormat.Png); // Format values are Bmp, Gif, Jpeg, Png, Tiff
Solution 2:[2]
I use noksa for full screen screenshots and I'm seeing the ToBitMap(); included. It comes with the imagemagick version that noksa installs. This is the code I have that works. Granted I havent used a bitmap before so I dont know if this bitmap created here will work for what you want, but I didnt get any error when creating it. I used a google terms page so you can see the quality of the screenshot.
public static void Scraps()
{
//Initiate Browser Instance
IWebDriver driver = InitBrowser("chrome");
//Go to Page of google terms
driver.Url = "https://www.google.com/intl/en_ZZ/policies/terms/archive/20070416/";
//Declare VCD which combines the various screenshots taken into one
VerticalCombineDecorator vcd = new VerticalCombineDecorator(new ScreenshotMaker());
//Declare Destination Folder
string folder = @"C:\Users\User\Documents\test" + ".png";
//Take Screenshot and save
driver.TakeScreenshot(vcd).ToMagickImage().Write(string.Format(folder), ImageMagick.MagickFormat.Png);
//Take Screenshot and Create Bitmap
System.Drawing.Bitmap Screenshot = driver.TakeScreenshot(vcd).ToMagickImage().ToBitmap();
driver.Quit();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Marek Martyniak |
| Solution 2 | Isaac M |
