Java
In Java, cast the Webdriver to a TakeScreenshot
and then call its takeScreenshotAs() method
.
This will create a File
object, which you can then copy to a real disk file.
WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
Python
In Python, use the save_screenshot()
method of the webdriver.
from selenium import webdriver driver = webdriver.Firefox() driver.get('http://www.google.com/') driver.save_screenshot("c:\\tmp\\screenshot.png")
C#
In C#, cast the driver to a ITakesScreenshot
and then call its GetScreenshot
method.
You can then call SaveAsFile()
on the returned Screenshot
object.
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot(); ss.SaveAsFile(@"C:\tmp\screenshot.png", System.Drawing.Imaging.ImageFormat.Png);