如何在 Java 中使用 selenium Web 驱动程序模拟打印屏幕按钮
问候,维涅什
selenium
不支持,只有网页截图。但是你可以用Robot
它来做
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);
}
在 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);