"/" and ":" not accepted with 'type'

Asked by Tedi Roca

Whenever I try to enter a URL as follows it types only the first part of it (http) and throughs and exception when reaching ":" or "/".

openApp ("C:\\Program Files\\Internet Explorer\\iexplore.exe")
URL = "http://localhost:8080/web/"
type (Key.TAB + URL)

Error:

Traceback (most recent call last):
  File "C:\DOCUME~1\USER\LOCALS~1\Temp\sikuli-tmp5065863307217116264.py", line 4, in <module>
    type (Key.TAB + URL)
  File "C:\Program Files\Sikuli\sikuli-script.jar\Lib\sikuli\Region.py", line 160, in type
 at sun.awt.windows.WRobotPeer.keyPress(Native Method)

 at java.awt.Robot.keyPress(Unknown Source)

 at edu.mit.csail.uid.Region.doType(Region.java:666)

 at edu.mit.csail.uid.Region.type_ch(Region.java:764)

 at edu.mit.csail.uid.Region.type(Region.java:375)

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

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

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

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

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key code

Question information

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

should be URL = r"http://localhost:8080/web/"

python standards.

r" "

means raw string.

other wise you have to dereference each character.

give that a try and if not wait for a more experienced user.

Revision history for this message
eliteSKL (camaro70s) said :
#2
Revision history for this message
eliteSKL (camaro70s) said :
#3

please disregard my previous post. i thought i knew it. sorry for miss leading.

Revision history for this message
eliteSKL (camaro70s) said :
#4

url = "http://localhost:8080/web/"
openApp ("C:\\Program Files\\Internet Explorer\\iexplore.exe")
wait(6)
type(Key.TAB+url)

maybe you have to add a wait() method. to make your script work i had to add a 6 second wait()

Revision history for this message
eliteSKL (camaro70s) said :
#5

try updating your JVM and what version of Sikuli are you using?

Revision history for this message
SkaiCloud (flypilot43) said :
#6

You can use:

url = paste("http://localhost:8080/web/")

or

url = type("http://localhost:8080/web/")

I preffered pates because it's instant.

Revision history for this message
SkaiCloud (flypilot43) said :
#7

I think that error looks to me like your using Key.TAB incorrectly.

when using a key stroke command I like to store it in a function

example:

def HitTab():
     KeyDown(Key.TAB)
     wait(.20) #humanly possiable even if you were to press the key tab it will take about .50-.89 a of a second for your finger to left of the key so .20 is computerize fast.
     KeyUp(Key.TAB)

so in your case it should be something like:

url = "http://localhost:8080/web/"
openApp ("C:\\Program Files\\Internet Explorer\\iexplore.exe")
wait(6)
HitTab()
paste(url)

Just a bit of advice I would change the wait(6) to something like
wait("image of IE",20)

What your doing is telling sikuli to wait for the image of Internet Explorer to appear. If it appears it will execute the next line. If it dosnt appear your telling it to wait a total of 20 seconds before it throws an exception that it cant find it.

I don't like using Throwexceptions(FALSE) because I always want to know if sikuli cant find an image but some people does it.

Revision history for this message
eliteSKL (camaro70s) said :
#8

agreed wait(6) seconds is a sloppy way of doing it. becuase my computer is slow so wait(6) is a gut feeling on how long it takes IE to load. where as using the method stated by SkaiCloud is more "bullet proof".

i tried to help... :( i couldn't recreate the error.

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

Again the general recommendations around type() (still true with Sikuli X):

--- 1. use type only for special keys like TAB, ENTER, F4, ...

--- 2. use paste("some text") to write text to the current cursor location (no language problems)

--- 3. one type() === one key combination, that you would press manually (no concatenation of keys)
Why: SkaiCloud already mentioned it: you normally have to wait after typing (e.g. tabbing through entry fields and or GUI elements) to give the application time to react.
e.g.
type(" ", KEY_ALT); wait(0.5) # to open the window menu in Windows
type('x'); wait(0.5) # to maximize
type(Key.F4, KEY_ALT) # to close the window
# bad example (you could not concat this) - but that is the principle

To have a general timing parameter with type() is an actual feature request. I have type() wrapped in my own generic function.

--- 4. Try to use well defined short cuts instaed of tabbing around or searching/clicking in menus.

Revision history for this message
Tedi Roca (tedi-roca) said :
#10

Thanks RaiMan, that solved my question.

Revision history for this message
Tedi Roca (tedi-roca) said :
#11

Thanks all for your help.

I'm really happy as a new joiner of Sikulli of having experienced this prompt and complete support from the community!

The issue is solved with what RaiMan proposed summarizing all inputs.

Revision history for this message
Salfuman The Great (salfuman) said :
#12

Thanks, RaiMan.
Your post puts cristal clear the use of type and paste
It solved my problem with typing urls into IE