Sikuli enters text in wrong field although correct match is present

Asked by Christina Zrelski

I'm relatively new to Sikuli and I'm having a problem with entering text into a textfield. I'm using the sikuli-script.jar in version sikulix 1.0.1 within Eclipse IDE to write JUnit-based tests.

My problem is as follows:
At the beginning, I want to focus on a textfield using a previously taken screenshot and enter some text. This works fine.
On the same screen, right beneath this textfield, there is a second textfield, in which I'd also like to enter some text.
The text for the second textfield always gets entered into the first, too.

Here's a snippet from my script demonstrating the problem:

App app = App.focus("My Window");
Region wholeApp = app.window();

wholeApp.type("textfield_1.png", "text_1");
wholeApp.type("textfield_2.png", "text_2");
...

I always end up having the text "text_1 text_2" inside textfield_1, and no changes in textfield_2.

Interestingly, when I log the match for the second textfield to the console, it always outputs the correct one, i.e.
wholeApp.find("textfield_2.png")
detects the correct textfield. Then why is the text always entered into the wrong one?
The only difference between the two textfields is that the second one is prefilled with some content. Might this be the problem?

Has anyone experienced a similar problem and found a solution to that?
Thanks in advance!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

This seems to be the standard GUI-not-ready-for-the-next-action problem:
the click, that is done within type(), to move the caret to the field, comes too fast for the second type, so it is simply ignored.

try this:

have a
Screen s = new Screen();

somewhere at the beginning, so you have a global Region object to use for unspecific methods.

and then try this:

wholeApp.type("textfield_1.png", "text_1");
s.wait(0.5); // wait 0.5 seconds
wholeApp.type("textfield_2.png", "text_2");

Revision history for this message
Christina Zrelski (christina-zrelski) said :
#2

Thanks for the quick answer.
I tried that now, but - sadly - it didn't solve my problem, no matter how long I wait.

The problem somehow is that the focus of the cursor remains at the first textfield the whole time.
I just changed the code to:

wholeApp.type("textfield_1.png", "text_1");
wholeApp.type(Key.TAB)
wholeApp.type("textfield_2.png", "text_2");

and now it works perfectly fine.

Is there any other solution to force a focus change? Because hard-coding the press of the TAB-key isn't really the best approach for creating long-living robust GUI-tests (since a future change in the GUI, i.e. adding another component in between the existing ones might break the testcase again).

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Since you said, that you have checked, that "textfield_2.png" leads to the correct match, I excluded the second most often failure situation: matching false positives (which would mean, that "textfield_2.png" matches textfield_1 too)

So as long as you are unsure, just show the matches using the highlight feature.
the easiest option:
Settings.Highlight=true;

from now on every match will be highlighted for 2 secs and the match is being logged with it's parameters.

Switch off again:
Settings.Highlight=false;

Revision history for this message
Christina Zrelski (christina-zrelski) said :
#4

When I turn Settings.Highlight on, the second textfield is surrounded by a red border - so the match seems to be correct.
But after the highlighting, the text still gets entered into the first textfield.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

ok, that's odd and must have to do with some behavior of your app.

test this:
Settings.Highlight=true;
wholeApp.type("textfield_1.png", "text_1");
//wholeApp.type(Key.TAB);
//wholeApp.type("textfield_2.png", "text_2");
wholeApp.type("textfield_2.png");
wholeApp.hover() // should move the mouse to field 2
s.wait(3)
wholeApp.click() // should click here and move the caret to fields
s.wait(3)
s.type("text_2");

the wait()'s are only to slow down for watching

Another option you have:
wholeApp.type("textfield_1.png", "text_1\n");
wholeApp.type("textfield_2.png", "text_2\n");

might be an ENTER is needed, to un-focus the textfield

Can you help with this problem?

Provide an answer of your own, or ask Christina Zrelski for more information if necessary.

To post a message you must log in.