Examples
Wait before taking screenshot with C# and Selenium
Install Selenium for .NET
dotnet add package Selenium.WebDriver
dotnet add package Selenium.Support Selenium.WebDriver 4.11+ includes Selenium Manager, which downloads the right chromedriver automatically. Selenium.Support is only needed for WebDriverWait in the wait example. The examples use C# top-level statements — put them in Program.cs of a console project and run with dotnet run.
Take a screenshot and save to file
Wait for the page to settle before taking the screenshot.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
var options = new ChromeOptions();
options.AddArgument("--headless=new");
using var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://www.htmltoimage.com/demo");
// Wait for late content — here an element that appears after 2 seconds.
// (WebDriverWait lives in the Selenium.Support package.)
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(d => d.FindElement(By.CssSelector("#delayed-banner")).Displayed);
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile("wait.png");
driver.Quit(); Find out how to take a full-page screenshot with C# and Selenium.
That was 19 lines of code — plus a browser to run in production
Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:
curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com" Try the Urlbox screenshot API — free trial, no browser babysitting.