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

How do I take the screenshot and pass the path of the PNG into click method and wait method?? kindly help.

PS: I want to open firefox browser, click in the address bar, enter a website name and click enter.

Thanks!

Mike
  • 899
  • 9
  • 27
  • 45

4 Answers4

3

As explained here, just provide the path to the PNG image corresponding to the screenshot.

That screenshot can be created with any screenshot utility. I used to script with sikuli IDE which provides a simple way to create screenshots.

Hope it helped.

phsym
  • 1,364
  • 10
  • 20
  • 1
    Thank you for the reply. When I execute the code, I encounter an exception(however the firefox is opened). Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\muralikrishna.b.IN\AppData\Local\Temp\tmplib\VisionProxy.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703) at java.lang.Runtime.load0(Runtime.java:770) at java.lang.System.load(System.java:1003) – Mike Aug 28 '12 at 10:05
  • Can you post the exception stack trace ? – phsym Aug 28 '12 at 10:05
  • Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\muralikrishna.b.IN\AppData\Local\Temp\tmplib\VisionProxy.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703) at java.lang.Runtime.load0(Runtime.java:770) at java.lang.System.load(System.java:1003) at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44) at org.sikuli.script.Finder.(Finder.java:33) at org.sikuli.script.Regi... – Mike Aug 28 '12 at 10:07
  • Seems like it can't find a native shared library – phsym Aug 28 '12 at 10:18
  • Check the existency of **C:\Users\muralikrishna.b.IN\AppData\Local\Temp\tmplib\VisionProxy.dll** – phsym Aug 28 '12 at 11:05
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)));
}

I hope this methode helps, it has worked for me ;)

Marko
  • 20,385
  • 13
  • 48
  • 64
Ahmed J.
  • 46
  • 1
1

Sikuli code to handle your PS request.

A few lines of description:

Line 3: I open a new tab so that the address bar always looks the same (different urls in the bar might register as different images). This is a major programming requirement of Sikuli, ignoring areas of a display that might change slightly over the use of the program. You could also reduce the percent comparison of an image.

Line 4: Sikuli finds the address bar picture (image is from FF in Windows). You can adjust the location on the image that Sikuli clicks or make sure that your image is large enough that the middle is a click on the address bar location (ie instead of Sikuli clicking on the globe icon). The url text that I defined in line 1 is typed into the selected address bar. The \n in the url is the enter key.

spearson
  • 1,016
  • 8
  • 18
  • Still trying to figure out...! Can u please help me with more info... Thanks!! – Mike Aug 30 '12 at 08:28
  • You are right, I can open the firefox browser.. I am trying to understand, 'How would I click on the address bar in FF browser and enter a text and click enter(Keyboard enter)' – Mike Aug 30 '12 at 08:42
  • Are you writing all your code in Java? If so, get some of your functions working with Sikuli IDE. The interface is much better. Once that is done you can copy/paste the raw code into your java program. – spearson Aug 30 '12 at 16:37
0

Sikuli

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

sikulix

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();        }
                }
    });
}
Yash
  • 9,250
  • 2
  • 69
  • 74