Typing variables

Asked by Queue

I am trying to type something I have stored as a variable; said variable is a string of text but when I say type($Variable) it throws the error java.util.UnknownFormatConversionException: java.util.UnknownFormatConversionException: Conversion = 'D'.

I haven't coded in some time but I can't think of any reason this wouldn't be working.

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
Queue (jcy2k03) said :
#1

In an attempt to get around this issue I've tried brute forcing the things I need to enter (there are quite a few of them) and I'm actually getting the same error when I say type("https://aces2.lsac.org/YourStatus/membership/AppStatIdMe.aspx?guid=iHj7FEgQQYY%3D")... Odd...

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

No idea, type() works for me with variables and text (Mac 10.6).

Only heard about weird things with keyboardlayouts ...
For typing text they recommend: Try paste(instead), if you have a target in focus where you can paste something in.

For keystrokes you still have to use type: e.g. type(Key.TAB) or type("n", KEY_CTRL). paste() uses the clipboard.

Maybe you have to check your java installation.

Revision history for this message
Garrett Bartley (wgbartley) said :
#3

Try the variable without the $.

I made up a quick script to test with and without the $. It does not work with the $ for me.

Sample script:

variable="Test"
switchApp("notepad.exe")
type(variable)

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

Correct as I just learned.
Already the line
$x = "something"
leads to an error

Variables in Python have to start with a letter. after that you can use letters, numbers and the underline only (case sensitive).

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

think this is anserwed

Revision history for this message
Queue (jcy2k03) said :
#6

It is and it isn't. Further testing has showed that the problem I was having was not the $, I just was denoting any variable; the problem is that type() cannot resolve the '%' character that I was trying to pass in my variable string. Hence instead of simply using

type("https://aces2.lsac.org/YourStatus/membership/AppStatIdMe.aspx?guid=iHj7FEgQQYY%3D")

I have to use

type("https://aces2.lsac.org/YourStatus/membership/AppStatIdMe.aspx?guid=iHj7FEgQQYY")
type("5",KEY_SHIFT)
type("3D")

Which is a) far more unwieldy, b) offends common sensibilities regarding a bit of code's beauty and c) makes scaling this project substantially more complicated than saying

def OpenURLinNewTab(URL)
   type("t",KEY_CMD)
   sleep(4) #let iGoogle load
   type("l",KEY_CMD)
   type(URL)
   type(Key.ENTER)
   login() #Other function with my log in info for these several pages
   return

URL = "URL_1"
OpenURLinNewTab(URL)
URL = "URL_2"
OpenURLinNewTab(URL)
...
URL = "URL_k"
OpenURLinNewTab(URL)

For my arbitrary URLs URL_1 to URL_k.

I cannot fathom why the % character would throw an error when passed into type()...

Revision history for this message
Garrett Bartley (wgbartley) said :
#7

Can you try escaping the % by putting a \ in front of it?

Revision history for this message
Queue (jcy2k03) said :
#8

No dice. Same error. I submitted another question under this topic so if this one should be closed let me know but the basic escape didn't do it.

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

Again (as stated before):

use paste() instead of type().

This works perfectly for putting something into input fields (like the browser address field) that have the focus (which should be the case in your script).

The single percent is interpreted as the formatting operator (don't ask me why in this case). The python way to escape the % is to use %% for one. this works (no error) but it types %% instead of %. The traceback shows, that the error starts with the Sikuli type module. may be the wrong java functions are used.

x="%%%s" % "abc%3D" # use of the formatting operator
print x # works: %abc%3D
type(x) # error
paste(x) # works too

its weird, because this means, the string givben to type() containing a % is interpreted as as a formatting string, without the %-operator being there.
I will report a bug

Revision history for this message
Queue (jcy2k03) said :
#10

Thanks RaiMan, that solved my question.