简体   繁体   中英

How to set focus to a window in java.awt.Robot

I am using selenium web driver to automate my web application. I am using java.awt.robot class to take screenshots. When i run my test it will open the browser and it will perform as i need and it will take the screenshot of the front window on the desktop screen.

Actual need:

I minimized the screen of browser window which is opened by selenium and doing some other action in some application. In that case my test case will execute perfectly but the screenshot is not the browser window it is the application which i opened.

My need is to take the screenshot of the browser window when it was minimized too.

Is it possible to do using Robot ? I am not saying I need screenshot by using robot class alone. Please suggest me other ways too.

Please consider I need the screenshot with out using TakesScreenshot class of selenium API.

As far as I know, we won't be able to use Robot class to take snapshot of Browser window if we are upto something else on the screen. It's to capture whatever happening on your PC screen which is currently active there. Thanks

Try this:

 File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(scrFile, new File(System.getProperty("user.dir")+"\\\\screenshots\\\\"+fileName+".jpg")); } catch (IOException e) { e.printStackTrace(); } 

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