Cannot click on browser window to enter URL

Asked by Atish

I am running Skilui 0.10.2 on Windows XP.

My objective is to open a browser and type an URL in the URL window.

The code is as follows:

openApp("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
sleep(5)
find("C:/Documents and Settings/alahiri/Local Settings/Temp/tmp--787388627.sikuli/1282339521580.png")
type("finance.yahoo.com")

I get the following error:

ScreenMatchProxy loaded.
VDictProxy loaded.
Win32Util loaded.
ScreenMatchProxy loaded.
[sikuli] Stopped
[sikuli] An error occurs at line 3
[sikuli] Error message:
Traceback (most recent call last):
  File "C:\DOCUME~1\alahiri\LOCALS~1\Temp\sikuli-tmp1801713819665661889.py", line 3, in <module>
    find("1282339521580.png")
  File "C:\ACLTools\Sikuli\sikuli-script.jar\Lib\sikuli\Region.py", line 59, in find
  Line 4, in file C:\DOCUME~1\alahiri\LOCALS~1\Temp\sikuli-tmp1801713819665661889.py

 at edu.mit.csail.uid.Region.wait(Region.java:240)

 at org.python.proxies.sikuli.Region$Region$1.super__wait(Unknown Source)

 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 at java.lang.reflect.Method.invoke(Unknown Source)

edu.mit.csail.uid.FindFailed: FindFailed: 1282339521580.png can't be found.
  Line 4, in file C:\DOCUME~1\alahiri\LOCALS~1\Temp\sikuli-tmp1801713819665661889.py

The .PNG file is definitely present in the specified directory.

Any help would be much appreciated.

Thanks in advance!

Atish

Question information

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

The message means, that your picture cannot be found on the screen at the time of the find() (exception FindFailed). The message is a little bit weird, since it could be misunderstood as a File-Not-Found error.

Before relying on openApp in your script, just open Firefox manually and go to the IDE and try your workflow. If you don't want to use a click() to activate the window, use switchApp("Firefox"), to switch to the open Browser window.
With workflows like this, I always open a new Browser window (type("n", KEY_CTRL)) and sometimes switch this window to fullscreen (type(Key.F11), to be "alone" on the screen. Then you are ready to type your url, since the cursor is positioned correctly.

so your script could look like this:
# start Firefox manually before running the script
switchApp("Firefox")
wait(1)
type("n", KEY_CTRL)
type(Key.F11) # optional for fullscreen
type("finance.yahoo.com")
type(Key.ENTER)

Now the page should be loaded. You can check it like this:
if not exists(an-image-on-finance.yahoo.com, 10): # wait max. 10 seconds for the page
    popup("Sorry, finance.yahoo.com may be down") # page did not come up
click(image-of-some-button)

If your workflow runs, you can now implement a startup sequence for Firefox if necessary.

one more thing: sometimes using type() you may run into timing problems: the next action after the type may fire to early. My experience is in these cases: add a short wait afterwards:
type("n", KEY_CTRl); wait(0.3) # between 0.1 and 0.5 normally is sufficient

Keep in mind you are programming in Python language (indentation, # for comments, more than one statement on a line use ; ...)

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

correction: (without the comments to be clear with indentation and added an exit())

if not exists(an-image-on-finance.yahoo.com, 10):
    popup("Sorry, finance.yahoo.com may be down")
    exit(1) # script should stop here
click(image-of-some-button)

Revision history for this message
Atish (alahiri) said :
#3

Hi RaiMan,

Many thanks for your quick response and please accept my sincere apologies for not replying to your answers to my question.

I was very busy with my official work and didn't get time to try out the options you gave - I will do so soon.

Best wishes,

Atish

Revision history for this message
Bruno Vieira (giuliapo) said :
#4

Just to add something.
If you press F6 on Firefox or Internet Explorer (at least these two) you get the focus on the URL and you can then paste your link or type it.
This is useful if you don't want to open a new tab that normally by default puts the focus on the URL already.

type(Key.F6)

It's important to let the browser start before typing. It might not be ready to receive input instantly.
You can wait for the homepage to appear for instance or simply check if the browser buttons appear and then wait 1 or 2 seconds.

Revision history for this message
Atish (alahiri) said :
#5

Hi Bruno and RaiMan,

Many thanks for all your help.

I was actually trying to do this the visual programming way and finally figured out what I was doing wrong.

Essentially, the problem happens when I specify the image as the beginning part of the URL box.

If I specify the image as the ending part of the URL box, Siklui finds it OK, types the URL in and takes me to the correct page.

What worked was:

openApp("C:\\Program Files\\Mozilla Firefox\\firefox.exe")
sleep(5)
type( <image of last part of URL box>, "finance.yahoo.com\n")

(Note: I can't paste the image here, so I just described it above)

Best wishes,

Atish