SHARE
TWEET

How to Capture Screen shot using Java for selenium webdriver

SeleniumETrainR Dec 13th, 2012 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.concurrent.TimeUnit;
  4.  
  5. import org.apache.commons.io.FileUtils;
  6. import org.openqa.selenium.OutputType;
  7. import org.openqa.selenium.TakesScreenshot;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10.  
  11.  
  12. public class TakesScreenshotTest {
  13.  
  14.          
  15.          
  16.                 public static void main(String[] args) throws IOException {
  17.                         WebDriver myTestDriver = new FirefoxDriver();
  18.                         myTestDriver.get("http://tinyurl.com/6d7xz7k");
  19.                         myTestDriver.manage().window().maximize();
  20.                         myTestDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
  21.  
  22.                         File scrFile = ((TakesScreenshot)myTestDriver).getScreenshotAs(OutputType.FILE);
  23.                     FileUtils.copyFile(scrFile, new File("c:\\careerbuilder.jpg"));
  24.                    
  25.                     myTestDriver.quit();
  26.                 }
  27.  
  28.  
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top