gpt4 book ai didi

java - Java 中的 Sikuli - 如何捕获屏幕截图/Png?

转载 作者:搜寻专家 更新时间:2023-11-01 02:13:32 24 4
gpt4 key购买 nike

public class MyFirstSikuliTest {    
public static void main(String[] args) {
App.open("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
Screen s = new Screen();
try{
s.click("How do I take the screenshot and pass the path of the PNG here?", 0);
s.wait("How do I take the screenshot and pass the path of the PNG here?");
s.type(null, "WEBSITE NAME", 0);
}
catch(FindFailed e){
e.printStackTrace();
}
}
}

如何截图并将PNG的路径传递给点击方法和等待方法?请帮忙。

PS:我要打开firefox浏览器,点击地址栏,输入网站名称,点击回车。

谢谢!

最佳答案

public static void takePictureOfError(String Name) throws IOException,
AWTException {
new File("Errors").mkdir();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
utilsLogger.info(ImageIO.write(image, "png", new File("//"
+ Name)));
}

我希望这个方法对我有帮助,它对我有用;)

关于java - Java 中的 Sikuli - 如何捕获屏幕截图/Png?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12156700/

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