I can agenerate random numbers, need to type them

Asked by Colby Black

New to programming, self taught.

I have a 365 line code that works really good for logging into multiple emails and adding filters. I need to ad a filter that includes randomly generated numbers (or letters). I figured out how to generate random numbers, and show them within sikuli, but I can't figure out how to take that randomly generated number and type it in the field I need it to. Please help thanks.

import random
print random.randrange(10000000000,10000000000000)

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
RaiMan (raimund-hocke) said :
#1

import random
num = random.randrange(10000000000,10000000000000)
type(str(num))

works if the input field has focus already.

otherwise your have to somehow give focus before or with the type (click(...), type(Key.TAB), ...)

Revision history for this message
Colby Black (coboblack) said :
#2

Thanks Rai!

Will check it out when I get home and will drop back here and let u know if it works for me.

Revision history for this message
Colby Black (coboblack) said :
#3

Rai

I typed it as a test

click("HndowZIh.png")
import random
num =
random.randrange(100000000, 100000000000000)
type(str(num))

and got this error

[error] Stopped
[error] An error occurs at line 3
[error] Error message: SyntaxError: ("no viable alternative at input '='", ('C:\\Users\\user\\AppData\\Local\\Temp\\sikuli-tmp6939699859182269962.py', 3, 4, 'num = \n'))

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

ok, that is basic Python knowledge: statements must be on one line or you use the continuation character \

click("HndowZIh.png")
import random
num = random.randrange(100000000, 100000000000000)
type(str(num))

Revision history for this message
Colby Black (coboblack) said :
#5

Hello,

Sorry to be a pain. (I've never programmed or taken any classes, so treat me like a retard =)

I tested this....

doubleClick("SearchIEssVi.png")
import random
num = random.randrange(100000000, 100000000000000)
type(str(num))

and it successfully completed it and it logged it as

[log] DOUBLE CLICK on (450,131)

[log] TYPE "45766032731841"

so it worked in generating the number,, but it never actually typed the random number it generated where I asked it to. (Which is the most important part) I need to type it outside of sikuli...not inside. Can you please type the code exactly how it should be if you wanted it to type in the randomly generated number in word?

Thanks and again, sorry for the ignorance.

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

This is what I mentioned in my first comment:
type() works if the input field has focus already.

This simply means (like you do that manually), that you have to activate Word somehow and then take care, that the caret is positioned and activated somewhere in Word, where you can type in something (usually the document).
In your case I suppose, that Word is already opened.

So if this is the intention of the doubleClick(), then you now have to check, what is wrong with it:
- it seams to find the image "SearchIEssVi.png", since it clicks
- by this click: is the desired input area selected and ready to accept keyboard input?

So you might try this, to clarify:

import random # only once at top of script

# doubleClick("SearchIEssVi.png")
# for debugging, we split this into:
m = find("SearchIEssVi.png") # finds the image
m.highlight(2) # red frame to show, what was found
doubleClick(m) # doubleClick it

wait(1) # we wait 1 second, to give time to the GUI

num = random.randrange(100000000, 100000000000000)
type(str(num))

wait(5) # wait 5 seconds to be able to see what happened on screen

The first wait can be reduced to a working minimum value, if it turns out, that it works with a wait.
The bloated doubleClick() can be reduced to one statement again, if it works.

*** I've never programmed or taken any classes,
That is not really necessary, to get basic workflows running with Sikuli script.
But if you want to be happy with it for a longer time and increasing complexity, then you need some basic knowledge about Python scripting (see faq 1858).

Revision history for this message
Colby Black (coboblack) said :
#7

Thanks RaiMan, that solved my question.

Revision history for this message
Colby Black (coboblack) said :
#8

You are awesome, sir =D

Funny, the code didn't not work in note++ or word, even when the cursor was there already....BUT, when I attempted it in gmails login field, it worked perfect. Soooo not sure why it worked one place and not the other. I'm aware of needing to focus on a field and clicking it before you attempt to type...thats how i get it to log in the emails, not sure why it wasn't working.