Is it possible to take a screenshot using Selenium WebDriver?
(Note: Not Selenium Remote Control)
Three ways to Capture Screenshots with Selenium WebDriver.
Selenium has the TakesScreenshot interface to capture the screenshots during execution of your Selenium script. The TakesScreenshot interface has a method named getScreenshotAs( ) which can capture a screenshot and store it in any location specified by us.
captureScreenshot (name of screenshot) - Selenium IDE command. captureEntirePageScreenshot takes a screenshot of the whole web page. captureScreenshot takes a screenshot of the visible website part (viewport). This command has the side effect of giving the tab that runs the macro the focus.
Yes, it is possible. The following example is in Java:
WebDriver driver = new FirefoxDriver(); driver.get("http://www.google.com/"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy somewhere FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With