Sikuli4Net: how to use targetOffset()

Asked by Kenneth.P on 2018-08-16

Hi.

I've been trying to search pretty much everywhere for a solution to my problem.
But i have'nt been able to find it.

Im trying to use Sikuli for Visual studio 2017 (C#)

So far i got some of it working. I can find images and i can click and send text.
But i can't get things like .targetOffset() to work, it does'nt recognize the command.

Btw i' m new to programming so examples are appreciated :)

This is my current code:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using Sikuli4Net.sikuli_UTIL;
using Sikuli4Net.sikuli_REST;

private void button1_Click(object sender, EventArgs e)
        {
            APILauncher launch = new APILauncher();
            Pattern Image1 = new Pattern(@"C:\Users\Elliot\Desktop\Sikuli Images\Login.PNG");
            Pattern Image2 = new Pattern(@"C:\Users\Elliot\Desktop\Sikuli Images\Type-Email.PNG");

            ChromeOptions options = new ChromeOptions();
            ChromeDriverService service = ChromeDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = true;
            options.AddArgument("--disable-infobars");
            var driver = new ChromeDriver(service, options);

            driver.Manage().Window.Size = new Size(1900, 1080);
            driver.Url = "http://www.google.dk/";

            Sikuli4Net.sikuli_REST.Screen scr = new Sikuli4Net.sikuli_REST.Screen();
            scr.Click(Image1);
            scr.Type(Image2, "MyEmailHere");
        }

            // I want to do something similar to this

            scr.Click(Image1).targetOffset(300, 0);

            // Error message: Operator '.' cannot be applied to operand of type 'void'

I hope someone can tell me what i'm missing?

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Kenneth.P
Solved:
2018-09-26
Last query:
2018-09-26
Last reply:
2018-08-16
RaiMan (raimund-hocke) said : #1

Though you are using Sikuli4Net (a wrapper for SikuliX), it makes sense to read the docs about SikuliX.

start here: http://sikulix.com

targetOffset() is a method of a Pattern object.

Kenneth.P (kenneth-philipsen) said : #2

Just a quick followup.

I figured it out some time ago. So i just want to share incase anyone else had the same problem.

So i switched from Sikuli4Net to SikuliSharp

Below is an example of how to set offset in SikuliSharp (C#)

private void button1_Click(object sender, EventArgs e)
        {
            using (var session = Sikuli.CreateSession())
            {
                SikuliSharp.Point offsetLogin = new SikuliSharp.Point(50, 0); // Adds an offset (x, y) from the center of the picture.
                SikuliSharp.Point offsetLogin2 = new SikuliSharp.Point(0, +200, 0); // Adds an offset (x + 200, y) With this you can set the offset outside the picture borders.

                IPattern loginImage = Patterns.FromFile(@"C:\Users\Elliot\Desktop\Sikuli Images\UserName.PNG");

                while (!session.Exists(loginImage))
                {
                    Thread.Sleep(500);
                }

                session.Click(loginImage, offsetLogin);
                session.Type("<email address hidden>");
                session.Dispose();
            }
        }