input text field into pop-up box

Asked by lvp on 2020-03-11

Hi there,
I started sikulix very very recently and have no programming knowledge. I have written a small script using built-in sikulix windows operations like click <screenshot>, type ("xxxxxx"), click <screenshot> ,wait,click <screenshot>. It may not be the the most efficient script, but it helps.

It works, when I have my password pre-populated in the script itself. But I plan to share my script with my pals as an exe, and they each have a different password (obviously).

so the issue is: Instead of pre-populating the password text in the script, I'd like to input that filed into the pop-up box which comes up during the running of script, by using a locally stored text file (or any file).

PS: I tried the solution provided in https://answers.launchpad.net/sikuli/+question/204153, but inserting the below snippet at line3 (by replacing my original line Type ("xxxxx"). I get an error.

*** working script:

click( screenshot )
click (Screenshot)
type("xxxxxx")
click (screenshot)
wait(2)
click(Screenshot)

*** Script to replace pre-populated password line
click( screenshot )
click (Screenshot)

import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
password = config.get('user1','password')

click (screenshot)
wait(2)
click(Screenshot)

>>config.ini file
user1
password = xxxxxx

Please may I know how to achieve this?

Thank you.

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2020-03-11
Last reply:
2020-03-11
Manfred Hampl (m-hampl) said : #1

If you are talking about a password, then I would never store it in the script or in a config file, but I suggest request it from the user at run time.

Something like

click( screenshot )
click (Screenshot)
myPassword = input("please enter your password", hidden = True)
paste(myPassword)
click (screenshot)
wait(2)
click(Screenshot)

In your approach with a config file, your error probably is that the config key "user1" has to be in brackets.
config.ini file:
[user1]
password = xxxxxx

(and you probably missed the paste() in your snippet)

lvp (lvpa) said : #2

Yeah, I agree its not good to store password in a file, but for my requirement I believe it is fine to do it :)

so, i included the bracket [user1 ] in config file and included paste( ) in the script . still get the below error.

[error] script [ Trial ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\lvp\Desktop\Trial.sikuli\Trial.py", line 11, in <module> pin = config.get('user1','pin') File "C:\Users\lvp\Downloads\sikulix.jar\Lib\ConfigParser.py", line 607, in get ConfigParser.NoSectionError: No section: 'user1'

**Edited script:

click( screenshot )
click (Screenshot)

import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.ini')
password = config.get('user1','password')
paste()

click (screenshot)
wait(2)
click(Screenshot)

>>config.ini file
[user1]
password = xxxxxx

RaiMan (raimund-hocke) said : #3

not a SikuliX question.

check how to use the ConfigParser modul correctly.

Manfred Hampl (m-hampl) said : #4

You script and the error message do not fit together.
The error message refers to a statement that is not contained in the script snippet!

lvp (lvpa) said : #5

Please may I know if there any way to input text from file in sikulix other than using ConfigParser ?

Manfred Hampl (m-hampl) said : #6

see https://answers.launchpad.net/sikuli/+question/204153 comment #1

Not a SikuliX question, but plain Python. Read books or web pages about Python.

Can you help with this problem?

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

To post a message you must log in.