4
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的路径传递给click方法和wait方法?请帮助。

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

谢谢!

4

4 回答 4

3

here所述,只需提供与屏幕截图对应的PNG图像的路径即可。

可以使用任何屏幕截图实用程序创建该屏幕截图。我曾经使用sikuli IDE编写脚本,它提供了一种创建屏幕截图的简单方法。

希望它有所帮助。

于 2012-08-28T09:54:16.207 回答
3
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)));
}

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

于 2012-10-03T17:24:55.080 回答
1

用于处理您的 PS 请求的 Sikuli 代码。

几行描述:

第 3 行:我打开一个新选项卡,以便地址栏看起来始终相同(栏中的不同 url 可能注册为不同的图像)。这是 Sikuli 的主要编程要求,忽略了可能会因使用程序而略有变化的显示区域。您还可以减少图像的百分比比较。

第4行:Sikuli找到地址栏图片(图片来自Windows中的FF)。您可以调整 Sikuli 单击的图像上的位置,或确保您的图像足够大,以使中间是单击地址栏位置(即,而不是 Sikuli 单击地球图标)。我在第 1 行中定义的 url 文本被输入到选定的地址栏中。url 中的 \n 是回车键。

于 2012-08-28T17:04:07.373 回答
0

西库里

public static void screenClipUser() throws IOException{
    org.sikuli.script.Screen screen = Screen.getPrimaryScreen();
    org.sikuli.script.Region region = screen.selectRegion("Select Area to capture as Image");
    ScreenImage clip = region.getLastScreenImage(); // screen.userCapture();
    ScreenImage printScreen = region.getScreen().capture();
    javax.imageio.ImageIO.write(clip.getImage(), "PNG", new File("D:\\SikuliImages\\Clip.png"));
    ImageIO.write(printScreen.getImage(), "PNG", new File("D:\\SikuliImages\\PrintScreen.png"));
    screenCaptureRegion(screen);
}
public static void screenCaptureRegion(Screen screen) throws IOException{
    java.awt.Point point = MouseInfo.getPointerInfo().getLocation();
    System.out.println("Mouse Location Co-Ordinates Previous Selected : " + point);
    //ScreenImage capturedRegion = screen.capture(point.x, point.y, 200, 200);
    ScreenImage capturedRegion = screen.capture(clip.x, clip.y, clip.w, clip.h);
    ImageIO.write(capturedRegion.getImage(), "PNG", new File("D:\\SikuliImages\\CapturedRegion.png"));
}

西库利克斯

public static void screenClipOneNote(){
    org.sikuli.script.IScreen scr = null;
    org.sikuli.script.EventObserver ob = null;
    final OverlayCapturePrompt oc = new org.sikuli.script.OverlayCapturePrompt(scr, ob);
        oc.prompt("Select Area to capture as Image");
        oc.addObserver(new org.sikuli.script.EventObserver() { // Inner calss
            @Override
            public void update(org.sikuli.script.EventSubject arg0) {
                org.sikuli.script.ScreenImage capturedImg = oc.getSelection(); // To use oc object make as final.
                try { 
                    ImageIO.write(capturedImg.getImage(), "PNG", new File("D:\\SikuliImages\\ScreenClip.png"));
                } catch (Exception e) {     e.printStackTrace();        }
                }
    });
}
于 2015-09-30T06:16:10.530 回答