简体   繁体   中英

How to capture Screenshot in Selenium2 using Java, need to capture popup window with its parent window(Browser) when browser is minimized

I tried using Robot class with BufferedImage screenImage = robot.createScreenCapture(screenRect) but it captures the active Screen only. Consider the Browser(Firefox) launched by Webdriver is minimized then this method doesn't capture Browser screen, instead it captures the active screen.

Please try below code if you are working with webdriver & java. It will capture the screenshot.

File ScreenShot = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.FILE);
StringBuilder FileName = new StringBuilder("Path or FolderLocation");
FileName.append(ScreenshotFirstName);
FileName.append("_");
FileName.append(dateFormat.format(date).toString());
FileName.append(".jpeg");
FileUtils.copyFile(ScreenShot, new File(FileName.toString()));

It will save the screenshot file with date and time appended to it and to a specific folder location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM