gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:31:03 25 4
gpt4 key购买 nike

如何在 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);

关于java - 如何在Java中使用selenium webdriver模拟打印屏幕按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19048119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com