Possible to repeat the same task but change one variable a field?

Asked by Bear

I have a task that i wish to make things a bit easier. My task is simple I usually have a list of #'s in a text file and I have to click 5 things on the windows app after i enter in each number. I was wondering if its possible for Sikuli to Read a .txt file and enter in the first number on the list click 5 things for me then read and enter the next number then click 5 things again.

Text file # example
123131231
123123131
231312318
123123123
231231678

Task
Sikuli reads text file pulls up first # > Enters it in a program field > Click 5 menu thing in the program > reads the text file again pulls the next #

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Roman Podolyan
Solved:
Last query:
Last reply:
Revision history for this message
Best Roman Podolyan (podolyan-roman) said :
#1

Sure it is.

Here is demo-code.
______
print sys.path[0]
# Prints to console the directory script was launched in

f1 = open(sys.path[0] + '\\5lines.txt', 'r')
# Reads a file

strings = f1.readlines()

f1.close()

for line in strings:
    popup(line)
    #put your code here
_______

To demo it, create a Sikuli file with code like above, and text file with name 5lines.txt in the same directory with the lines you need
_____
First
Second
Third
Fourth
Fifth
______

After running this, I see 5 popups with strings from the text file.

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#2

You can put any code where popup(line) is now, and that code, be it clicking or whatever, will run as many times as there are lines in file, 5 times for 5 lines, 6 for 6 lines, etc.

Revision history for this message
Bear (bear-questions) said :
#3

Thanks amazing! will give it a try =)

Revision history for this message
Bear (bear-questions) said :
#4

Thanks Roman Podolyan, that solved my question.