简体   繁体   English

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

[英]How to simulate Print screen button using selenium webdriver in Java

How to simulate Print screen button using selenium web driver in Java如何在 Java 中使用 selenium web 驱动程序模拟打印屏幕按钮

Regards, Vignesh问候, 维涅什

selenium doesn't support it, only web page shots. selenium不支持,只支持网页截图。 However you can use Robot to do it但是你可以使用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);
}

And in C#在 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何测试或模拟使用Java在Selenium Webdriver中将文件从桌面拖动到浏览器 - How to test or simulate draging a file from desktop to browser in selenium webdriver using Java 如何使用带有Java的Selenium WebDriver多次单击同一按钮 - How to click on a same button multiple times using Selenium WebDriver with Java 如何使用带有Java的Selenium WebDriver选择单选按钮? - How to select radio button using Selenium WebDriver with Java? 如何使用Java使用Selenium WebDriver验证是否单击了按钮 - How to verify whether a Button is clicked or not with Selenium WebDriver using Java 如何通过使用Java在Selenium Webdriver中的弹出窗口上单击允许按钮 - How to click on allow button on popup window in selenium Webdriver by using Java 如何通过使用Java在Selenium Webdriver中的弹出窗口上单击按钮 - How to click on button on Popup Window in Selenium Webdriver by using Java 如何使用XPath不是常数的Selenium WebDriver Java单击按钮 - How to click button using selenium webdriver java, whose xpath is not constant 如何使用带有 Java 的 Selenium WebDriver 单击按钮? - How can I click on a button using Selenium WebDriver with Java? 如何使用Selenium Web Drivver拍摄当前窗口的屏幕截图或模拟打印屏幕 - How to take screenshot of Current window or simulate print screen using selenium web drivver 无法单击 selenium webdriver 中的“按钮”(使用 Java) - Unable to click the 'button' in selenium webdriver (using Java)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM