如何使用Java中的selenium webdriver模拟打印屏幕按钮

时间:2013-09-27 10:08:00

标签: selenium selenium-webdriver

如何使用Java中的selenium web驱动程序模拟打印屏幕按钮

此致 维涅什

1 个答案:

答案 0 :(得分:4)

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