How to simulate Print screen button using selenium web driver in Java
Regards, Vignesh
How to simulate Print screen button using selenium web driver in Java
Regards, Vignesh
selenium
doesn't support it, only web page shots. However you can use Robot
to do it
try {
String format = "jpg";
String fileName = printScreen." + format;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, format, new File(fileName));
} catch (AWTException | IOException ex) {
System.err.println(ex);
}
And in C#
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(@"C:\ScreenShots\printScreen.jpg", ImageFormat.Jpeg);