简体   繁体   English

如何使用Java在Selenium2中捕获屏幕截图,需要在最小化浏览器时捕获带有其父窗口(浏览器)的弹出窗口

[英]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. 我尝试将Robot类与BufferedImage screenImage = robot.createScreenCapture(screenRect)但它仅捕获活动的Screen。 Consider the Browser(Firefox) launched by Webdriver is minimized then this method doesn't capture Browser screen, instead it captures the active screen. 考虑最小化由Webdriver启动的Browser(Firefox),然后此方法不捕获浏览器屏幕,而是捕获活动屏幕。

Please try below code if you are working with webdriver & java. 如果您正在使用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. 它将保存屏幕快照文件,并附加日期和时间以及特定的文件夹位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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