如何在Java中使用硒网络驱动程序模拟打印屏幕按钮

2022-09-03 16:03:07

如何在Java中使用硒Web驱动程序模拟打印屏幕按钮

问候, 维格内什


答案 1

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);

答案 2

推荐